iOS 5.0之前的版本并没有开放控制系统亮度的接口,所以app能做到的只是比系统设置的亮度更暗,具体做法就是在整个app的keywindow之上再放一个window,设置黑色背景,通过控制alpha值来达到明暗变化。
- (void)installBrightnessWindow { m_brightnessWindow = [[UIWindow alloc] initWithFrame:self.view.window.frame]; m_brightnessWindow.windowLevel = UIWindowLevelStatusBar + 1; m_brightnessWindow.userInteractionEnabled = NO; m_brightnessWindow.backgroundColor = [UIColor blackColor]; m_brightnessWindow.alpha = 0; m_brightnessWindow.hidden = NO; }
具体方法请查看demo:
http://download.csdn.net/detail/hursing/5183100
5.0以及之后,可以这样调节屏幕亮度,对整个系统生效:
[UIScreen mainScreen].brightness = 0.5;