iOS QR界面亮度调整

亮度调事,不久在QR界面切换的时候还要考虑进入前台后台时的操作

1.QR界面功能实现代码。

objectivec 复制代码
QR界面

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    [[NSUserDefaults standardUserDefaults] setValue:@([UIScreen mainScreen].brightness) forKey:@"Brightness"];
    
    [UIScreen mainScreen].brightness = 1;
}

- (void) viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    NSNumber* num = [[NSUserDefaults standardUserDefaults] objectForKey:@"Brightness"];
    
    if(num.floatValue > 0.1)
    {
        [UIScreen mainScreen].brightness = num.floatValue;
    }
}

2.进入前后台时的处理。这个地方要意思,必须要在Appdelegate

中的两个回调函数中实现,在QR()中添加进入前后台通知实现的话,会有问题。具体原历不清楚

  • (void)applicationDidBecomeActive:(UIApplication *)application

  • (void)applicationWillResignActive:(UIApplication *)application

objectivec 复制代码
- (void)applicationDidBecomeActive:(UIApplication *)application {
    application.applicationIconBadgeNumber = 0;
    
    if(当前界面是QR界面)
    {
    	[UIScreen mainScreen].brightness = 1; 
    }
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    NSNumber* num = [[NSUserDefaults standardUserDefaults] objectForKey:@"Brightness"];
    
    if(num.floatValue > 0.1)
    {
        [UIScreen mainScreen].brightness = num.floatValue;
    }
    
    NSLog(@"num = %@", num);
}
相关推荐
初级代码游戏3 天前
easy Photo Clean公测版:快速清理iPhone照片 邀请公测
ios·iphone
库奇噜啦呼3 天前
【iOS】RunLoop学习
学习·ios
黑科技iOS上架3 天前
iOS应用周末提交什么情况算卡审
经验分享·ios
zzb15803 天前
ios基础-MVC-UIView
ios·mvc·cocoa
kingbal3 天前
Flutter:Flutter SDK版本管理工具FVM
android·flutter·ios·android-studio·window
他们都不看好你,偏偏你最不争气3 天前
【iOS】Runtime - Part 2 && 消息发送:缓存、查找与转发
macos·ios·objective-c·cocoa
2501_915918414 天前
iOS App性能测试工具的实现方法与优化循环指南
android·ios·小程序·https·uni-app·iphone·webview
他们都不看好你,偏偏你最不争气4 天前
【iOS】Runtime - Part 1 && 对象与类的本质
macos·ios·objective-c·cocoa