遮罩实现镂空

    [self.view setBackgroundColor:[UIColor redColor]];

    

    UIView *guideView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];

    guideView.backgroundColor = [UIColor blackColor];

    guideView.alpha = 0.6;

        

    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRect:self.view.bounds];

    [maskPath setUsesEvenOddFillRule:YES];

    //镂空的path

    UIBezierPath *rectPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(100, 100, 200, 150) cornerRadius:10];

    [maskPath appendPath:rectPath];

 

    CAShapeLayer *maskLayer = [CAShapeLayer layer];

    maskLayer.path = maskPath.CGPath;

    maskLayer.fillRule = kCAFillRuleEvenOdd;

 

    guideView.layer.mask = maskLayer;

    [self.view addSubview:guideView];

效果如下:

遮罩实现镂空_第1张图片

效果如下

你可能感兴趣的:(iOS,Core,Aniamtion,Ad,Tech,IOS)