使iPhone屏幕变暗 [英] Make the iPhone Screen Dim

查看:234
本文介绍了使iPhone屏幕变暗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已设法确保iPhone不会自动锁定:

I have managed to ensure that the iPhone doesn't auto-lock using:

    [[ UIApplication sharedApplication ] setIdleTimerDisabled: YES ];

但是如何在一段时间后使屏幕变暗?

But how do I make the screen dim after a certain amount of time?

谢谢...

编辑:

认为我找到了我自己的解决方案:

Think I've found a solution myself:

在视图控制器中使用此方法,通过添加50%alpha的黑色视图来调暗。确保设置userInteractionEnabled = NO以将事件传递给基础视图。

Use this method in your view controller to dim by adding a black view with 50% alpha. Make sure to set userInteractionEnabled = NO to pass events to underlying views.

- (IBAction)dim:(id)sender {
UIView *dimView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
dimView.backgroundColor = [UIColor blackColor];
dimView.alpha = 0.5f;
dimView.userInteractionEnabled = NO;
[self.view addSubview:dimView];
}

或者,可能有风险(但Apple可能会拒绝提交):

or, could risk it (but Apple may reject on submission):

[(id)[UIApplication sharedApplication] setBacklightLevel:1.0f];

这是私有API,不应该使用...

That's a private API and shouldn't be used though...

推荐答案

从iOS 5开始, UIScreen 类中有一个公共API。它有一个亮度属性,可以设置。对于那些您可能想要比实际背光允许更暗的情况,有一个 wantsSoftwareDimming 属性会自动放置一个半透明的层,使外观更暗淡比硬件更好。这与您提出的半透明 UIView 的方法非常相似。应该注意的是,使用您的解决方案或软件调光API不应该与许多动画一起使用,因为您将在所有alpha混合中支付性能损失。

As of iOS 5 there is a public API in the UIScreen class. It has a brightness property that can be set. For those instances where you may want to go dimmer than the actual backlight allows, there is a wantsSoftwareDimming property that will automatically place a translucent layer that will give the appearance of being more dim than can be done in hardware. This is very similar to the method you came up with with the translucent UIView. It should be noted that using your solution or the software dimming API should not be used with many animations since you will pay a performance penalty with all the alpha blending.

参见< a href =http://developer.apple.com/library/IOs/#documentation/UIKit/Reference/UIScreen_Class/Reference/UIScreen.html>UIScreen类参考

这篇关于使iPhone屏幕变暗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆