扫一扫黑色背景掏洞demo
2016-09-02 本文已影响16人
走道牙的人
// 可以扫描的区域
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;