如何在 iOS 5 应用程序中更改亮度?
我如何编程改变应用程序内的亮度?我知道这是可能的,因为我已经看到至少三个应用程序可以做到这一点。这对我的应用程序非常有用。我知道这只能在 iOS 5 中通过 UIScreen 类实现,但我不知道如何对其进行编程。请帮我!
How would I program the ability to change brightness in-app? I know that its possible as I have seen at least three apps that can do it. This would be very useful for my app. I know that it's only possible in iOS 5 with the UIScreen Class, but I have no idea how to program it. Please help me!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
UIScreen
类有一个新的 名为brightness
的属性。此外,还有另一个名为
wantsSoftwareDimming
的属性(当设置为YES
时)允许您低于硬件支持的最低亮度,因为特殊的“调光视图”是覆盖在屏幕上使事物进一步变暗。brightness
属性采用从0
到1
的浮点数。因此:wantsSoftwareDimming
设置为NO
(默认值)时,亮度
为0
表示“硬件中最暗的”支持”,亮度
为1
表示“硬件支持的最亮”。wantsSoftwareDimming
设置为YES
时,亮度
为0
表示“硬件支持的最暗值,并且通过覆盖调光视图”,亮度
为1
仍然意味着“硬件支持的最亮”。The
UIScreen
class has a new property calledbrightness
.In addition, there's another property called
wantsSoftwareDimming
that (when set toYES
) allows you to go below the lowest brightness supported by the hardware, because a special "dimming view" is overlaid over the screen to darken things even further.The
brightness
property takes a float from0
to1
. So:wantsSoftwareDimming
set toNO
(the default), abrightness
of0
means "the darkest the hardware supports" and abrightness
of1
means "the brightest the hardware supports".wantsSoftwareDimming
set toYES
, abrightness
of0
means "the darkest the hardware supports PLUS darkening by overlaying a dimming view", and abrightness
of1
still means "the brightest the hardware supports".我从未尝试过,但查看文档应该是这样的:
I have never tried it, but looking at the docs it should go like this:
正如其他人指出的那样,您可以使用
但是要非常小心,因为您会遇到问题(根据这里的经验进行讨论)
看看这个:
IOS5 setBrightness 不适用于 applicationWillResignActive
还有这个:
任何人都能够使用[[UIScreen mainScreen] setBrightness] 在后台/退出?
(我希望我有,当我发现这个线程/答案时):-(
As others pointed out you can use
BUT be very careful because you will run into problems (talking from experience here)
look at this:
IOS5 setBrightness didn't work with applicationWillResignActive
and this:
Anyone been able to use [[UIScreen mainScreen] setBrightness] on background / exit?
(I wish I had, when I discovered this thread/answer) :-(
您可以使用以下两者之一:
[[UIScreen mainScreen]setBrightness:1.0];
GSEventSetBacklightLevel(0.5f);
但这是一个私有 API 调用,如果您使用它,您的应用程序肯定会被拒绝。You can use either of these two:
[[UIScreen mainScreen]setBrightness:1.0];
GSEventSetBacklightLevel(0.5f);
But this is a private API call, if you use it, your application will surely be rejected.