最近在做人脸识别,相机界面需要中间一个圆为透明,圆外部分半透明,用贝塞尔曲线实现如下:
//画周围白色半透明区域
CAShapeLayer *pShapeLayer = [CAShapeLayer layer];
pShapeLayer.fillColor = [UIColor colorWithWhite:1 alpha:0.6].CGColor;
pShapeLayer.frame = overView.frame;
[overView.layer addSublayer:pShapeLayer];
//圆弧
UIBezierPath *pPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(HALFABOUTUISCREEN_WIDTH, HALFABOUTUISCREEN_HIGHT - kCircleCenterY)
radius:self.bounds.size.width / 2.0 + self.progressStrokeWidth / 2.0 startAngle:0.0 endAngle:M_PI * 2 clockwise:YES];
pShapeLayer.path = pPath.CGPath;
//矩形
UIBezierPath *pOtherPath = [UIBezierPath bezierPathWithRect:
CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
pShapeLayer.path = pOtherPath.CGPath;
[pOtherPath appendPath:pPath];
pShapeLayer.path = pOtherPath.CGPath;
//重点
pShapeLayer.fillRule = kCAFillRuleEvenOdd;