需求是只留下一塊圓形區(qū)域可以看見下面視圖的內(nèi)容沿彭,其他地方遮住。
//背景
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.coverView.bounds cornerRadius:0];
//中間鏤空的圓
CGPoint center = CGPointMake(100, 100);
UIBezierPath *circlePath = [UIBezierPath bezierPathWithArcCenter:center radius:100 startAngle:0 endAngle:M_PI*2 clockwise:YES];
[path appendPath:circlePath];
[path setUsesEvenOddFillRule:YES];
CAShapeLayer *fillLayer = [CAShapeLayer layer];
fillLayer.path = path.CGPath;
fillLayer.fillRule = kCAFillRuleEvenOdd;
fillLayer.fillColor = UIColor.redColor.CGColor;
fillLayer.opacity = 1.0;
self.fillLayer = fillLayer;
[self.coverView.layer addSublayer:fillLayer];
需要生成其他形狀术羔,只需要把circlePath替換成其他形狀的路徑即可。
希望對你有用乙漓。