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);
}
相关推荐
Nick56831 小时前
Xcode16 避坑
ios
ii_best1 小时前
IOS/ 安卓开发工具按键精灵Sys.GetAppList 函数使用指南:轻松获取设备已安装 APP 列表
android·开发语言·ios·编辑器
2501_915909061 小时前
iOS 26 文件管理实战,多工具组合下的 App 数据访问与系统日志调试方案
android·ios·小程序·https·uni-app·iphone·webview
hweiyu001 小时前
苹果iOS开发零基础特训(视频教程)
ios
2501_9159184115 小时前
掌握 iOS 26 App 运行状况,多工具协作下的监控策略
android·ios·小程序·https·uni-app·iphone·webview
2501_9159090618 小时前
iOS 混淆实战,多工具组合完成 IPA 混淆与加固(源码 + 成品 + 运维一体化方案)
android·运维·ios·小程序·uni-app·iphone·webview
非专业程序员Ping1 天前
新手小白也能看懂的LLDB技巧/逆向技巧
ios·assembly
QWQ___qwq1 天前
SwiftUI 布局之美:Padding 让界面呼吸感拉满
ios·swiftui·swift