扫一扫黑色背景掏洞demo

// 可以扫描的区域
CGRect rect = CGRectMake((DBScreenW - 188) / 2.0, (DBScreenH - 188) / 2.0, 188, 188);

UIView *maskView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
maskView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
[self.scanView addSubview:maskView];

// 配置不能扫描区域的遮罩
UIBezierPath *path = [UIBezierPath bezierPathWithRect:[UIScreen mainScreen].bounds];
[path appendPath:[[UIBezierPath bezierPathWithRect:rect] bezierPathByReversingPath]];

CAShapeLayer *shapeLayer = [[CAShapeLayer alloc] init];
shapeLayer.path = path.CGPath;
maskView.layer.mask = shapeLayer;

你可能感兴趣的:(扫一扫黑色背景掏洞demo)