所以我试图从现有图层中切出一个圆圈;这是我的代码:
CGRect bounds = _containerLayer.bounds;
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = bounds;
maskLayer.fillColor = [UIColor blackColor].CGColor;
CGFloat smallCircleRadius = (frame.size.width - barWidth)/2;
CGRect smallCircleRect = CGRectMake(CGRectGetMidX(bounds) - smallCircleRadius, CGRectGetMidY(bounds) - smallCircleRadius, 2 * smallCircleRadius, 2 * smallCircleRadius);
UIBezierPath *circlePath = [UIBezierPath bezierPathWithOvalInRect:smallCircleRect];
[circlePath appendPath:[UIBezierPath bezierPathWithRect:bounds]];
maskLayer.path = circlePath.CGPath;
maskLayer.fillRule = kCAFillRuleEvenOdd;
_containerLayer.mask = maskLayer;
此代码确实有效,因为我现在看到一个黑色矩形,中间有一个空心圆圈。但问题是,当我尝试设置maskLayer.fillColor = [UIColor clearColor].CGColor;
时,包括_containerLayer
在内的整个事情就会消失 - 我想让fillColor
变得透明,这样我才能看到{{1}中最初的内容(没有删除)。我该怎么做才能做到这一点?谢谢!