ios中的夜间模式(通知中心)
2015-10-31 21:19
489 查看
这个夜间模式不是颜色反转的那种,其实很简单,就是在window上面铺了一层view,把这个view的变成黑色,在调一下透明度就ok了,下面给大家看看代码实现吧
这段代码要在AppDelegate中实现:
- (instancetype)init { self = [super init]; if (self) { NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; [center addObserver:self selector:@selector(receiveNotifica:) name:@"heiyejianglin" object:nil]; // 白天模式 NSNotificationCenter *center2 = [NSNotificationCenter defaultCenter]; [center2 addObserver:self selector:@selector(receiveNotifica2:) name:@"limingjianglin" object:nil]; } return self; }
- (void)receiveNotifica:(NSNotification *)center { self.nigView.hidden = NO; NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"value",@"key", nil]; [[NSNotificationCenter defaultCenter]postNotificationName:@"limingjianglinla" object:@"香皂" userInfo: dic]; }
- (void)receiveNotifica2:(NSNotification *)center { self.nigView.hidden = YES; NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"value",@"key", nil]; [[NSNotificationCenter defaultCenter]postNotificationName:@"heiyejianglinla" object:@"香皂" userInfo: dic]; }
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.nigView = [[UIView alloc] initWithFrame:self.window.bounds]; self.nigView.userInteractionEnabled = NO; self.nigView.hidden = YES; self.nigView.backgroundColor = [UIColor blackColor]; self.nigView.alpha = 0.6; [self.window addSubview:self.nigView]; [_nigView release]; return YES; }
- 这段代码要在你加夜间模式中的开关方法中实现
if (button) { // NSLog(@"是"); NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"value",@"key", nil]; [[NSNotificationCenter defaultCenter]postNotificationName:@"heiyejianglin" object:@"香皂" userInfo: dic]; }else { // NSLog(@"否"); NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"value",@"key", nil]; [[NSNotificationCenter defaultCenter]postNotificationName:@"limingjianglin" object:@"香皂" userInfo: dic]; }
相关文章推荐
- YTKNetwork 使用高级教程
- ios开发Swif语言基本的参数、函数、方法的定义和调用
- iOS优化25条建议
- IOS优化
- iOS系统开发:发“彩信”
- #在蓝懿学习iOS的日子#第三个练习日
- iOS系统开发:打电话、发短信
- IOS开发涉及有点概念&相关知识点
- RSA加密算法在iOS9下的问题解决方案
- iOS开发中正则式的使用
- iOS-CALayer && CAAnimation
- iOS开发:定时器与滚动视图的交互
- iOS 中去掉tableview中多余的cell
- 高仿IOS---Dialog(底部式)
- iOS中 输入账户密码错误时的抖动提示
- iOS 设计模式-Block实现代理的逻辑
- iOS 9 适配系列教程
- 解决[服务器证书无效, 连接伪装服务器]问题
- 会员中心选项添加提示信息
- iOS常用框架