本文介绍: 效果图 ,和第二种情况是一样的,因为滤镜视图添加到了self.view上面,并且self.view 白色的,滤镜的灰色就不会穿透。添加灰色滤镜是图的时候,滤镜视图从滤镜被添加到的视图开始向上穿透,知道被有背景言色的视图挡住为止。view2 由于是透明色,被灰色滤镜穿透了,view3是白色,没有被穿透。view 是透明色,滤镜添加到 view上面,view 被穿透了。由于这时候view的背景色是白色,就不会穿透了,所以完全成了白色。和第一种情况是一样的。
添加灰色滤镜方法
@implementation TPBlackWhiteScreenTool
+ (void)addGrayFilterToView:(UIView *)view {
if (@available(iOS 13.0,*)) {
[view.kGrayView removeFromSuperview];
UIView *greyView = [[UIView alloc] initWithFrame:view.bounds];
greyView.userInteractionEnabled = NO;
greyView.backgroundColor = [UIColor lightGrayColor];
greyView.layer.compositingFilter = @"saturationBlendMode";
greyView.layer.zPosition = FLT_MAX;
[view addSubview:greyView];
view.kGrayView = greyView;
}
}
调用
情况 一
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
UIView *view = [[UIView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:view];
view.backgroundColor = [UIColor clearColor];
[TPBlackWhiteScreenTool addGrayFilterToView:view];
UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
view2.backgroundColor = [UIColor clearColor];
[view addSubview:view2];
UIView *view3 = [[UIView alloc] initWithFrame:CGRectMake(100, 300, 100, 100)];
view3.backgroundColor = [UIColor whiteColor];
[view addSubview:view3];
}
view 是透明色,滤镜添加到 view上面,view 被穿透了
view2 由于是透明色,被灰色滤镜穿透了,view3是白色,没有被穿透
情况二
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
UIView *view = [[UIView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:view];
view.backgroundColor = [UIColor whiteColor];
[TPBlackWhiteScreenTool addGrayFilterToView:view];
UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
view2.backgroundColor = [UIColor clearColor];
[view addSubview:view2];
UIView *view3 = [[UIView alloc] initWithFrame:CGRectMake(100, 300, 100, 100)];
view3.backgroundColor = [UIColor whiteColor];
[view addSubview:view3];
}
效果图
由于这时候view的背景色是白色,就不会穿透了,所以完全成了白色
情况三
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
[TPBlackWhiteScreenTool addGrayFilterToView:self.view];
UIView *view = [[UIView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:view];
view.backgroundColor = [UIColor clearColor];
UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
view2.backgroundColor = [UIColor clearColor];
[view addSubview:view2];
UIView *view3 = [[UIView alloc] initWithFrame:CGRectMake(100, 300, 100, 100)];
view3.backgroundColor = [UIColor whiteColor];
[view addSubview:view3];
}
效果图 ,和第二种情况是一样的,因为滤镜视图添加到了self.view上面,并且self.view 白色的,滤镜的灰色就不会穿透
![请添加图片描述](https://img–blog.csdnimg.cn/9ad4af6ee04f4f46a4f3a3c68fe603c4.png = x600)
情况四
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
[TPBlackWhiteScreenTool addGrayFilterToView:self.view];
UIView *view = [[UIView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:view];
view.backgroundColor = [UIColor clearColor];
UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
view2.backgroundColor = [UIColor clearColor];
[view addSubview:view2];
UIView *view3 = [[UIView alloc] initWithFrame:CGRectMake(100, 300, 100, 100)];
view3.backgroundColor = [UIColor whiteColor];
[view addSubview:view3];
}
和第一种情况是一样的
结论
添加灰色滤镜是图的时候,滤镜视图从滤镜被添加到的视图开始向上穿透,知道被有背景言色的视图挡住为止
原文地址:https://blog.csdn.net/LIUXIAOXIAOBO/article/details/128638179
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_37002.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。