iOS 页面置灰记录

iOS App 页面置灰部分原理记录

一、资源置灰

1、App内置相关资源和主体图片,根据相关时间后台下发指令来触发相关主题生效时间

2、App采用线上资源包、皮肤,动态下发到端上

二、控件置灰

给主要控件置灰,比如UIImage/UIColor/UIWebView等

1、遍历视图,依次对相关控件处理

2、采用hook方式,对相关控件hook特殊处理

三、App整体添加滤镜

1、UIView.layer上 添加灰色滤镜

// 最顶层视图,承载滤镜,自身不接收、不拦截任何触摸事件
@interface UIViewOverLay : UIView
@end
 
@implementation UIViewOverLay
-(UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    return nil;
}
@end
 
 
UIWindow *window = App的Window;
UIViewOverLay *overlay = [[UIViewOverLay alloc]initWithFrame:self.window.bounds];
overlay.translatesAutoresizingMaskIntoConstraints = false;
overlay.backgroundColor = [UIColor lightGrayColor];
overlay.layer.compositingFilter = @"saturationBlendMode";
[window addSubview:overlay];
 
最后通过各种方法,要保证overlay在最顶层.

2、私有API CAFilter添加滤镜

//获取RGBA颜色数值
CGFloat r,g,b,a;
[[UIColor lightGrayColor] getRed:&r green:&g blue:&b alpha:&a];
//创建滤镜
id cls = NSClassFromString(@"CAFilter");
id filter = [cls filterWithName:@"colorMonochrome"];
//设置滤镜参数
[filter setValue:@[@(r),@(g),@(b),@(a)] forKey:@"inputColor"];
[filter setValue:@(0) forKey:@"inputBias"];
[filter setValue:@(1) forKey:@"inputAmount"];
//设置给window
window.layer.filters = [NSArray arrayWithObject:filter];

四、效果展示

借助IMYAppGrayStyle Pod库,简单实现置灰效果

1、全局置灰

实现:AppDelegate 初始化处调用,IMYAppGrayStyle.open()

2、局部置灰

实现StudyManagerController 初始化地方,IMYAppGrayStyle.add(to: self.view)

参考:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值