我有这个捕获条形码的代码;它工作正常,除了在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
答案 0 :(得分:1)
只需创建一个取消按钮并将其添加到UIViewController的视图中。
按下按钮时,停止捕获会话并关闭显示的视图控制器。
- (void)cancelButtonPressed:(id)sender {
[self.captureSession stopRunning]; //stop the capture session
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil]; // dismiss the current view controller
}