/// view 添加透視區域
/// @param rect 區域的fram
/// @param cornerRadii 圓角的寬高
- (CAShapeLayer *)emptyLayerWithRect:(CGRect)rect cornerRadii:(CGSize)cornerRadii
{
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:(UIRectCornerTopLeft |UIRectCornerTopRight |UIRectCornerBottomRight|UIRectCornerBottomLeft) cornerRadii:cornerRadii];
UIBezierPath *pathBase = [UIBezierPath bezierPathWithRect:[UIScreen mainScreen].bounds];
[pathBase appendPath:bezierPath];
pathBase.usesEvenOddFillRule = YES;
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = pathBase.CGPath;
shapeLayer.fillColor= [UIColor blackColor].CGColor; //非透明顏色
shapeLayer.fillRule=kCAFillRuleEvenOdd;
return shapeLayer;
}
// 調用
self.view.layer.mask = [self emptyLayerWithRect:CGRectMake(10, 10, 60, 100) cornerRadii:CGSizeMake(5, 5)];