蒙板的代理方法如下:
/*** 蒙板生成,需設置代理,并在退出頁面時取消代理*/-(void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx{ if (layer == self.maskLayer) { UIGraphicsBeginImageContextWithOptions(self.maskLayer.frame.size, NO, 1.0); CGContextSetFillColorWithColor(ctx, [UIColor colorWithRed:0 green:0 blue:0 alpha:0.6].CGColor); CGContextFillRect(ctx, self.maskLayer.frame); CGRect scanFrame = [self.view convertRect:self.scanView.frame fromView:self.scanView.superview]; CGContextClearRect(ctx, scanFrame); }}
二維碼掃描的回調方法的具體實現(xiàn)如下:這里我用了一個遮蓋的框架SVProgressHUD,模擬一下掃描的等待過程,瞎裝一下。
-void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection { NSString *stringValue; // 顯示遮蓋 [SVProgressHUD show]; if