如何在 iOS 5 应用程序中更改亮度?

发布于 2024-12-17 01:54:43 字数 117 浏览 1 评论 0原文

我如何编程改变应用程序内的亮度?我知道这是可能的,因为我已经看到至少三个应用程序可以做到这一点。这对我的应用程序非常有用。我知道这只能在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

温柔嚣张 2024-12-24 01:54:43

UIScreen 类有一个新的 名为 brightness 的属性。

此外,还有另一个名为 wantsSoftwareDimming 的属性(当设置为 YES 时)允许您低于硬件支持的最低亮度,因为特殊的“调光视图”是覆盖在屏幕上使事物进一步变暗。

brightness 属性采用从 01 的浮点数。因此:

  • wantsSoftwareDimming 设置为 NO(默认值)时,亮度0 表示“硬件中最暗的”支持”,亮度1 表示“硬件支持的最亮”。
  • wantsSoftwareDimming 设置为 YES 时,亮度0 表示“硬件支持的最暗值,并且通过覆盖调光视图”,亮度1仍然意味着“硬件支持的最亮”。

The UIScreen class has a new property called brightness.

In addition, there's another property called wantsSoftwareDimming that (when set to YES) 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 from 0 to 1. So:

  • with wantsSoftwareDimming set to NO (the default), a brightness of 0 means "the darkest the hardware supports" and a brightness of 1 means "the brightest the hardware supports".
  • with wantsSoftwareDimming set to YES, a brightness of 0 means "the darkest the hardware supports PLUS darkening by overlaying a dimming view", and a brightness of 1 still means "the brightest the hardware supports".
不甘平庸 2024-12-24 01:54:43

我从未尝试过,但查看文档应该是这样的:

UIScreen *mainScreen = [UIScreen mainScreen];
mainScreen.brightness = .5; //should set the brightness at 50%

I have never tried it, but looking at the docs it should go like this:

UIScreen *mainScreen = [UIScreen mainScreen];
mainScreen.brightness = .5; //should set the brightness at 50%
梦归所梦 2024-12-24 01:54:43

正如其他人指出的那样,您可以使用

[[UIScreen mainScreen] setBrightness:1.0];

但是要非常小心,因为您会遇到问题(根据这里的经验进行讨论)
看看这个:
IOS5 setBrightness 不适用于 applicationWillResignActive
还有这个:
任何人都能够使用[[UIScreen mainScreen] setBrightness] 在后台/退出?

(我希望我有,当我发现这个线程/答案时):-(

As others pointed out you can use

[[UIScreen mainScreen] setBrightness:1.0];

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) :-(

勿忘心安 2024-12-24 01:54:43

您可以使用以下两者之一:

  1. [[UIScreen mainScreen]setBrightness:1.0];

  2. < p>GSEventSetBacklightLevel(0.5f); 但这是一个私有 API 调用,如果您使用它,您的应用程序肯定会被拒绝。

You can use either of these two:

  1. [[UIScreen mainScreen]setBrightness:1.0];

  2. GSEventSetBacklightLevel(0.5f); But this is a private API call, if you use it, your application will surely be rejected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文