在上面的文章中说的关于设置扫描区域,当时写的是手动计算的区域设置的
其实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];
}];
网友评论