/// 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)];