1. layer层 mask 遮罩效果
//渐变层
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = CGRectMake(, , kWidth, kWidth);
gradientLayer.colors = @[(__bridge id)[[UIColor redColor]colorWithAlphaComponent:0.4] .CGColor,
(__bridge id)[UIColor clearColor].CGColor];
gradientLayer.startPoint = CGPointMake(, );
gradientLayer.endPoint = CGPointMake(, ); [self.view.layer addSublayer:gradientLayer]; //
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(, , , )];
CAShapeLayer *layer = [CAShapeLayer layer];
layer.frame = self.view.bounds;
layer.lineWidth = ;
layer.strokeColor = [UIColor redColor].CGColor;
layer.fillColor = [UIColor redColor].CGColor;
layer.path = path.CGPath;
layer.lineCap = @"round";
// [gradientLayer addSublayer:layer]; gradientLayer.mask = layer;
2. maskView 实现局部透明效果
//0.相当于maskView 将自己"投影"到 view上, 注意层级关系, 实际并不是在'灰色'的view上滑动, 而是投影到了"灰色"的view上了
//1.设置了遮罩mask属性后, 只显示重叠部分
//2.可以通过改变遮罩的alpha和颜色实现透明、半透明的效果
UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:self.view.bounds];
imageView1.image = [UIImage imageNamed:@""];
[self.view addSubview:imageView1]; TestView *view = [TestView new];
view.frame = self.view.bounds;
view.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.9];
[self.view addSubview:view]; UIImageView *imageView = [[UIImageView alloc]initWithFrame:self.view.bounds];
imageView.image = [UIImage imageNamed:@""];
[self.view addSubview:imageView]; UIView *roundView = [[UIView alloc]initWithFrame: CGRectMake(, , , )];
roundView.backgroundColor = [UIColor redColor];
_viewwww = roundView;
imageView.maskView = roundView;