iOS並沒有開放控制系統亮度的接口,所以app能做到的只是比系統設置的亮度更暗,具體做法就是在整個app的keywindow之上再放一個window,設置黑色背景,通過控制alpha值來達到明暗變化。
[cpp]
- (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;
}
- (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;
}