半透明帮助页效果图
写了一个简单的demo
详细代码如下
- (void)viewDidLoad {
[super viewDidLoad];
//
[self setupShapLayer];
}
- (void)setupShapLayer {
// 1.创建一个遮罩View,并添加
UIView *maskView = [[UIView alloc] initWithFrame:self.view.bounds];
maskView.backgroundColor = [UIColor blackColor];
maskView.alpha = 0.6;
[self.view addSubview:maskView];
// 2.贝塞尔曲线 创建一个和 遮罩View 一样大小的 第一个 backgroudPath,并添加
UIBezierPath *backgroudPath = [UIBezierPath bezierPathWithRect:self.view.bounds];
// 贝塞尔曲线 创建第二个小矩形的 rectPath
CGFloat width = 160;
CGFloat height = 100;
CGFloat x = (self.view.bounds.size.width - width) * 0.5;
CGFloat y = 184;
UIBezierPath *rectPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(x, y, width, height) cornerRadius:10];
// rectPath 反转成矩形框以外的path
rectPath = [rectPath bezierPathByReversingPath];
// rectPath
rectPath.usesEvenOddFillRule = YES;
// 3.
[backgroudPath appendPath:rectPath];
// 4.创建一个CAShapeLayer 图层
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = backgroudPath.CGPath;
shapeLayer.fillColor = [UIColor yellowColor].CGColor; // 除了clearColor外任意颜色
shapeLayer.lineWidth = 10;
shapeLayer.borderColor = [UIColor redColor].CGColor;
shapeLayer.borderWidth = 20;
//添加图层蒙板
maskView.layer.mask = shapeLayer;
}
然后在modal出来的视图的背景色为clearColor,再添加其它视图,注意view的层级就行了