亮度调事,不久在QR界面切换的时候还要考虑进入前台后台时的操作
1.QR界面功能实现代码。
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文章来源:https://www.toymoban.com/news/detail-729860.html
- (void)applicationWillResignActive:(UIApplication *)application文章来源地址https://www.toymoban.com/news/detail-729860.html
- (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);
}
到了这里,关于iOS QR界面亮度调整的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!