2014-10-04 5 views
0

바코드를 캡처하는 코드가 있습니다. 그것은 iPad를 제외하고는 잘 작동합니다. iPad를 안정적으로 유지할 수 없다면, "내 생각에 젖소가 올 때까지 시도합니다." "취소"버튼을 추가하거나 메소드를 취소하는 방법을 찾아서 앱을 죽이고 다시 시작할 필요가 없습니다. 여기 내 코드는 다음과 같습니다.카메라 획득 코드에 '취소'버튼을 추가하는 방법은 무엇입니까?

- (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]; 
     [_prevLayer removeFromSuperlayer]; 
     [_label removeFromSuperview]; 

     break; 
    } 
    else 
     _label.text = @"(none)"; 
} 

} 

누군가이 문제에 대해 도움을 줄 수 있습니까? 나는 정말로 그것을 정말로 바르게 평가할 것이다! : D

답변

1

취소 버튼을 만들고 UIViewController의보기에 추가하기 만하면됩니다.

단추를 누르면 캡처 세션을 중지하고 표시된보기 컨트롤러를 닫습니다.

- (void)cancelButtonPressed:(id)sender { 
    [self.captureSession stopRunning]; //stop the capture session 
    [self.presentingViewController dismissViewControllerAnimated:YES completion:nil]; // dismiss the current view controller 
} 
+0

원래 코드가 무엇을하고 있었는지 (코멘트가 없어서) 알아 냈지만 이제는 챔피언처럼 작동합니다! 정말 고맙습니다! – SpokaneDude