人脸检测UI,要做一个镂空圆形,其余是黑色,但是黑色带有光圈渐变,就让ui直接出了一个背景色的图。
具体实现如下:
UIView *backgroundView = [[UIView alloc] init];
backgroundView.frame = self.bounds;
//背景色
backgroundView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.7];
[self addSubview:backgroundView];
UIImage *image = FH_IMAGE_FROM_BUNDLE(@"fh_background");
backgroundView.layer.contents = (id) image.CGImage;
// 创建一个全屏大的path
UIBezierPath *path = [UIBezierPath bezierPathWithRect:self.bounds];
// 创建一个圆形path
UIBezierPath *circlePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.center.x/2, self.center.y *3/2)radius:SCREEN_WIDTH/5 startAngle:0 endAngle:2 * M_PI clockwise:NO];
[path appendPath:circlePath];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = path.CGPath;
backgroundView.layer.mask = shapeLayer;
实现类似效果:
image.png
网友评论