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

2018-07-26  本文已影响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];
                                                  }];
上一篇 下一篇

猜你喜欢

热点阅读