[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];

效果如下:

遮罩实现镂空

效果如下

相关文章:

  • 2022-02-03
  • 2022-12-23
  • 2021-08-14
  • 2021-09-01
  • 2021-06-10
  • 2022-12-23
  • 2021-11-10
猜你喜欢
  • 2022-12-23
  • 2021-11-26
  • 2022-12-23
  • 2022-12-23
  • 2021-04-17
  • 2022-12-23
相关资源
相似解决方案