2014-08-31 1 views
0

내가 바코드 판독기를 추가 할 아이 패드 응용 프로그램을 가지고 ... 이것은 barcoder 코드의 초기화 코드입니다 :바코드를 스캔 한 후 UIView를 닫으려면 어떻게해야합니까?

-(void) scanInitializationCode { 

_highlightView = [[UIView alloc] init]; 
_highlightView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleBottomMargin; 
_highlightView.layer.borderColor = [UIColor greenColor].CGColor; 
_highlightView.layer.borderWidth = 3; 
[self.view addSubview:_highlightView]; 

// define the label to display the results of the scan 
_label = [[UILabel alloc] init]; 
_label.frame = CGRectMake(0, self.view.bounds.size.height - 40, self.view.bounds.size.width, 40); 
_label.autoresizingMask = UIViewAutoresizingFlexibleTopMargin; 
_label.backgroundColor = [UIColor colorWithWhite:0.15 alpha:0.65]; 
_label.textColor = [UIColor whiteColor]; 
_label.textAlignment = NSTextAlignmentCenter; 
_label.text = @"(none)"; 
[self.view addSubview:_label]; 

// session initialization 
_session = [[AVCaptureSession alloc] init]; 
_device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; 
NSError *error = nil; 

// define the input device 
_input = [AVCaptureDeviceInput deviceInputWithDevice:_device error:&error]; 
if (_input) { 
    [_session addInput:_input]; 
} else { 
    NSLog(@"Error: %@", error); 
} 

// and output device 
_output = [[AVCaptureMetadataOutput alloc] init]; 
[_output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()]; 
[_session addOutput:_output]; 

_output.metadataObjectTypes = [_output availableMetadataObjectTypes]; 

// and preview layer 
_prevLayer = [AVCaptureVideoPreviewLayer layerWithSession:_session]; 
_prevLayer.frame = self.view.bounds; 
_prevLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; 
[self.view.layer addSublayer:_prevLayer]; 

}

이는 AVCaptureMetadataOutputObjectsDelegate 코드 :

- (IBAction)aReadBarcode:(UIButton *)sender { 

[self scanInitializationCode]; 

[_session startRunning]; 

// display the activity 
[self.view bringSubviewToFront:_highlightView]; 
[self.view bringSubviewToFront:_label]; 

oISBNField.text = scanResults; 

} 
01 :
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection { 

CGRect highlightViewRect = CGRectZero; 
AVMetadataMachineReadableCodeObject *barCodeObject; 
NSString *detectionString = nil; 
NSArray *barCodeTypes = @[AVMetadataObjectTypeEAN13Code]; 

for (AVMetadataObject *metadata in metadataObjects) { 
    for (NSString *type in barCodeTypes) { 
     if ([metadata.type isEqualToString:type]) 
     { 
      barCodeObject = (AVMetadataMachineReadableCodeObject *)[_prevLayer transformedMetadataObjectForMetadataObject:(AVMetadataMachineReadableCodeObject *)metadata]; 
      highlightViewRect = barCodeObject.bounds; 
      detectionString = [(AVMetadataMachineReadableCodeObject *)metadata stringValue]; 
      break; 
     } 
    } 

    if (detectionString != nil) { 

     _label.text = detectionString; 
     oISBNField.text = detectionString; // move detectionString to ISBN textbox 
     [_session stopRunning]; 
     [_highlightView removeFromSuperview]; 
     break; 
    } 
    else 
     _label.text = @"(none)"; 
} 

이 사용자가있는 UIButton을 탭함으로써 스캐닝 프로세스를 시작 코드

일단 스캔이 바코드를 찾으면 표시가 유지되는 것이 문제입니다. 내가 원하는 것은 UIView에 스캔을 시작하게하는 버튼이있는 UIView로 돌아가는 것입니다. 즉, _highlightView이 사라지 길 원합니다. 나는 모든 종류의 "해고 (dismissal)"방법을 시도해 왔으며 심지어 z 순서의 뒤쪽에 놓았지만 아무도 작동하지 않습니다. 강조 표시을 화면에서 어떻게 사라지게 할 수 있습니까?

+0

그냥 강조 표시하고 싶은 뷰를 강조 표시 하시겠습니까? 'prevLayer'는 어떻습니까? – keeshux

답변

0

답 :

[_prevLayer removeFromSuperlayer]; after [_session stopRunning]

+0

나는 보통 유용한 의견을 upvote. =) – keeshux

관련 문제