http://ju.outofmemory.cn/entry/121291
https://blog.csdn.net/lc_obj/article/details/41549469
其他方法参考:
https://www.jianshu.com/p/3fb24fc7b415
AVCaptureMetadataOutput 中的属性rectOfInterest
假设你的相机显示屏幕的frame 为 x , y, w, h, 你要设置的矩形快的frame 为 x1, y1, w1, h1. 那么你的 rectOfInterest 应该设置为 CGRectMake(y1/h, x1/w, h1/h, w1/w).
_output = [[AVCaptureMetadataOutput alloc] init];
[_output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
//_scanFrame 为 你 扫描框的frame
CGRect scaleRect = CGRectMake(
(_scanFrame.origin.y)/kDeviceHeigh,
((kDeviceWidth-_scanFrame.size.width)/2)/kDeviceWidth,
_scanFrame.size.width/kDeviceHeigh,
_scanFrame.size.width/kDeviceWidth
);
NSLog(@" scaleRect : %@",[NSValue valueWithCGRect: scaleRect]);
[_output setRectOfInterest: scaleRect];