iOS view上添加透視區域

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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章