美文网首页
使用原生API扫描二维码设置扫描区域

使用原生API扫描二维码设置扫描区域

作者: 黑暗森林的歌者 | 来源:发表于2018-07-26 15:23 被阅读7次

使用原生API扫描二维码

在上面的文章中说的关于设置扫描区域,当时写的是手动计算的区域设置的

其实AVCaptureVideoPreviewLayer- (CGRect)metadataOutputRectOfInterestForRect:(CGRect)rectInLayerCoordinates是可以正常使用的,只不过不是直接调用这个方法,需要在通知回调中进行设置

  CGRect outRect = CGRectMake(10, 60, 200, 200);
[[NSNotificationCenter defaultCenter] addObserverForName:AVCaptureInputPortFormatDescriptionDidChangeNotification
                                                      object:nil
                                                       queue:[NSOperationQueue currentQueue]
                                                  usingBlock: ^(NSNotification *_Nonnull note) {
                                                      captureOutput.rectOfInterest = [captureLayer metadataOutputRectOfInterestForRect:outRect];
                                                  }];

相关文章

网友评论

      本文标题:使用原生API扫描二维码设置扫描区域

      本文链接:https://www.haomeiwen.com/subject/cxybmftx.html