以编程方式更改 iPhone 上的背光亮度

发布于 2024-07-11 11:11:54 字数 32 浏览 12 评论 0原文

SDK是否提供了改变背光亮度或暂时关闭背光的方法?

Does the SDK provide any way to change the brightness of the backlight, or turn it off temporarily?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(5

狼性发作 2024-07-18 11:11:54

我正在尝试做同样的事情。
碰巧的是,互联网上有很多帖子提供了针对此问题的“解决方案”。

最详细的是 这里
这个更加简洁

问题是我已经尝试过这些,它们都依赖于调用此函数

GSEventSetBacklightLevel();

,该函数需要导入此标头

#import <GraphicsServices/GraphicsServices.h>

,并且在 SDK 中导入失败,报告找不到头文件。

我已经寻找了一些解决方案但还没有找到。
有一些关于“构建工具链”的讨论(有关我找到的最佳描述,请参阅此处) 但这似乎涉及完全绕过 SDK。 相当激烈。

摘要:这是可能的,但不能使用标准 iPhone SDK。 我想 SDK 的更新很快就会到来,应该会允许这样做。

如果您找到任何其他解决方案,请告诉我。

I'm trying to do the same thing.
As it happens there are a number posts out there in the internets with "solutions" for this.

The most detailed is here
This one is more succinct

The problem is that I've tried these and they all rely on calling this function

GSEventSetBacklightLevel();

which requires this header to be imported

#import <GraphicsServices/GraphicsServices.h>

And that import fails in the SDK reporting that the header file cannot be found.

I've searched for some solution but haven't found it.
There is some talk about "building the toolchain" (for the best description I've found see here) but that seems to involve bypassing the SDK altogether. Pretty drastic.

Summary: It's possible, but not with the standard iPhone SDK. I imagine an update to the SDK will come soon that should allow for it.

Let me know if you find any other solution.

空城之時有危險 2024-07-18 11:11:54

不可以。SDK 中不提供此功能。 如果您认为它有用,我建议您提交增强请求

No. This is not available in the SDK. If it's something you think would be useful, I suggest you file an enhancement request.

残月升风 2024-07-18 11:11:54
-(void)changeLight{

    GSEventSetBacklightLevel(float number);//number between 0.0 - 1.0
}

调用上述方法,

[self performSelector:@selector(changeLight) withObject:nil afterDelay:0.0];

您只需从 /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/System/Library/PrivateFrameworks/GraphicsServices.framework 拖放到您的 xcode 项目中即可添加私有框架。

还要在 .h 文件中添加 #import "GraphicsServices.h" 标头。记住:由于您使用的是私有框架,您的应用程序将在应用商店推送中拒绝

-(void)changeLight{

    GSEventSetBacklightLevel(float number);//number between 0.0 - 1.0
}

call the above method using

[self performSelector:@selector(changeLight) withObject:nil afterDelay:0.0];

you can add the private framework by just drag and drop to your xcode project from /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/System/Library/PrivateFrameworks/GraphicsServices.framework.

Also add #import "GraphicsServices.h" header in your .h file..remember: since you are using private framework you application will reject in app store push

尘世孤行 2024-07-18 11:11:54

在我的 SDK (5.0.1) 中,“GraphicsServices.h”似乎不再存在,但您可以像这样自己声明它:

void GSEventSetBacklightLevel(float level);

请注意,链接器会抱怨,除非您在项目中包含框架 GraphicsServices.framework。

关于您关于关闭背光的问题,我发现您可以通过将一个非常大的负数传递给 GSEventSetBacklightLevel 来实现,如下所示:

GSEventSetBacklightLevel(-INFINITY);

在我的测试中,这将使屏幕完全变黑。

请记住,如果显示静态图形,即使背光关闭,这仍然可能会导致 LCD 像素烧屏。 并且如果提交到应用商店,此调用将导致拒绝。

In my SDK (5.0.1) it seems that "GraphicsServices.h" is no longer there, but you can declare it yourself like this:

void GSEventSetBacklightLevel(float level);

Note that the linker will complain, unless you include the framework GraphicsServices.framework in your project.

About your question about turning the backlight off, I found out that you can do it by passing a very large negative number to GSEventSetBacklightLevel, like this:

GSEventSetBacklightLevel(-INFINITY);

In my tests this will completely black out the screen.

Remember that this might still cause burn-in in the LCD pixels if you display static graphics, even when the backlight is off. And that this call will cause rejection if submitteed to app store.

时光是把杀猪刀 2024-07-18 11:11:54

试试这个代码。 我希望它有帮助...

//在viewWillAppear中

float prevBrightnessLevel = [UIScreen mainScreen].brightness;

[UIScreen主屏幕].brightness = 1.0;

//在viewWillDisappear

[UIScreen主屏幕].亮度=
上一页亮度级别;

try this code. i hope it helps...

//in viewWillAppear

float prevBrightnessLevel = [UIScreen mainScreen].brightness;

[UIScreen mainScreen].brightness = 1.0;

//in viewWillDisappear

[UIScreen mainScreen].brightness =
prevBrightnessLevel;

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