1. layer層 mask 遮罩效果spa
//漸變層 CAGradientLayer *gradientLayer = [CAGradientLayer layer]; gradientLayer.frame = CGRectMake(0, 100, kWidth, kWidth); gradientLayer.colors = @[(__bridge id)[[UIColor redColor]colorWithAlphaComponent:0.4] .CGColor, (__bridge id)[UIColor clearColor].CGColor]; gradientLayer.startPoint = CGPointMake(0, 0); gradientLayer.endPoint = CGPointMake(1, 0); [self.view.layer addSublayer:gradientLayer]; // UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 200, 200)]; CAShapeLayer *layer = [CAShapeLayer layer]; layer.frame = self.view.bounds; layer.lineWidth = 5; 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 實現局部透明效果code
//0.至關於maskView 將本身"投影"到 view上, 注意層級關係, 實際並非在'灰色'的view上滑動, 而是投影到了"灰色"的view上了blog
//1.設置了遮罩mask屬性後, 只顯示重疊部分it
//2.能夠經過改變遮罩的alpha和顏色實現透明、半透明的效果class
UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:self.view.bounds]; imageView1.image = [UIImage imageNamed:@"1"]; [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:@"1"]; [self.view addSubview:imageView]; UIView *roundView = [[UIView alloc]initWithFrame: CGRectMake(50, 50, 100, 100)]; roundView.backgroundColor = [UIColor redColor]; _viewwww = roundView; imageView.maskView = roundView;