[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];
效果如下:
效果如下