博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mask layer的遮罩层
阅读量:6991 次
发布时间:2019-06-27

本文共 1855 字,大约阅读时间需要 6 分钟。

 

1. layer层 mask 遮罩效果

//渐变层    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 实现局部透明效果

//0.相当于maskView 将自己"投影"到 view上, 注意层级关系, 实际并不是在'灰色'的view上滑动, 而是投影到了"灰色"的view上了

//1.设置了遮罩mask属性后, 只显示重叠部分

//2.可以通过改变遮罩的alpha和颜色实现透明、半透明的效果

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;

 

转载于:https://www.cnblogs.com/daxueshan/p/9379457.html

你可能感兴趣的文章
【二】调通单机版的thrift-C++版本
查看>>
让javascript加载速度倍增的方法(解决JS加载速度慢的问题)
查看>>
ASP.NET MVC 主要的四种过滤器和三种具体实现类
查看>>
Python中的正则表达式
查看>>
由于扩展配置问题而无法提供您请求的页面。如果该页面是脚本,请添加处理程序。如果应下载文件,请添加 MIME 映射...
查看>>
(转)结构体中使用string所引发的问题
查看>>
Linux查看网卡流量(转)
查看>>
论文修改(1)
查看>>
[javaEE] web应用的目录结构&配置虚拟主机
查看>>
[PHP] 数据结构-反转链表PHP实现
查看>>
MySQL 如何利用一条语句实现类似于if-else条件语句的判断
查看>>
jQuery和Zepto冲突问题【解决】
查看>>
machinekey生成工具 v1.0 官方最新版
查看>>
http server v0.1_mime.c
查看>>
open files
查看>>
MVC ——RouteTable.Routes的使用
查看>>
玩转X-CTR100 | STM32F4 l X-Assistant串口助手控制功能
查看>>
TCP/IP学习笔记1--概述,分组交换协议
查看>>
深入百度外链工具引发的思考
查看>>
DataBindings 与 INotifyPropertyChanged 实现自动刷新 WinForm 界面
查看>>