设置指定区域透明需要用到UIBezierPath
1.获取View
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRect:view.bounds];
2.设置指定区域
UIBezierPath *holePath = [UIBezierPath bezierPathWithRect:rect];
3.将透明区域拼接到主区域中
[maskPath appendPath:holePath];
4.将设置添加到view中
CAShapeLayer *mask = [CAShapeLayer layer];
[mask setFillRule:kCAFillRuleEvenOdd];
mask.path = maskPath.CGPath;
[view.layer setMask:mask];
网友评论