appdelegate 方法中的 setBrightness?
为什么我无法在 applicationDidEnterBackground 或 applicationWillResignActive 中设置屏幕亮度?
这是我的代码:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[[UIScreen mainScreen] setBrightness:1.0];
}
无法理解...!?它适用于 applicationDidEnterForeground 等,只是当我使用主页按钮关闭应用程序时不起作用。
感谢任何可以提供帮助的人...
Why can't I set screen brightness in applicationDidEnterBackground or applicationWillResignActive?
This is my code:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[[UIScreen mainScreen] setBrightness:1.0];
}
Can't understand it...!? It works in applicationDidEnterForeground etc, just not when i close the app using the home button.
Thanks to anyone that can help...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果你想改变亮度,你应该这样做:
If you want to change the brightess you should do that:
这可能是因为您的应用程序放弃了对操作系统的控制,然后操作系统将根据用户的全局设置来控制亮度。如果你想全局更改亮度设置,你必须访问用户的全局 iPhone 设置并更改它们,我不确定这是否可行。
当您在 applicationDidEnterForeground 上设置亮度时:您的应用程序再次处于控制状态,并且可以调整亮度等内容。一旦您的应用程序失去控制思想,操作系统就会接管并使设备恢复符合用户的全局设置。
希望有帮助。
It's probably because your app is relinquishing control to the OS, and the OS will then control the brightness according to the user's global settings. If you want to change the brightness setting globally, you'd have to access the user's global iphone settings and change them, and I'm not sure that's possible.
When you're setting the brightness on applicationDidEnterForeground: your app is in control again, and can adjust stuff like brightness. As soon as your app loses that control thought, the OS takes over and brings the device back into compliance with the user's global settings.
Hope that helps.
我很确定这是当前版本的一个错误(setBrightness 调用在 applicationDidEnterBackground 或 applicationWillResignActive 内部没有效果)。
我目前所做的与您所达到的类似 - 我在应用程序活动时将亮度设置为 1.0,然后在需要时通过修改所有其他图形顶部的黑色层的不透明度来降低亮度。这样,如果用户暂停应用程序,那么他们的屏幕至少是亮的(而不是应用程序所处的任意亮度)。
当用户锁定屏幕时,屏幕将恢复至 iPhone 设置中的亮度。
I'm pretty sure this is a bug with the current version (that the setBrightness call has no effect inside of either applicationDidEnterBackground or applicationWillResignActive).
What I do currently is similar to what you arrived at - I set the brightness to 1.0 on application active, and then reduce brightness when needed by modifying the opacity of a black layer on top of all other graphics. That way, if the user suspends the app, then their screen is at least bright (rather than at whatever arbitrary brightness the app was at).
When the user locks their screen, it will be restored to the brightness in their iPhone settings.