您现在的位置: IOS教程網 >> IOS系統 >  >> iOS 訊息 >> iOS 相關資訊

iOS 偽亮度調節的實作原理

編輯:iOS 相關資訊

由於 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;
}

透過改變 m_brightnessWindow.alpha 的大小,就能讓覆蓋在畫面上的黑色遮罩變深或變淺,進而營造出亮度調整的視覺效果。

  1. 上一篇文章:
  2. 下一篇文章:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © IOS教程網 All Rights Reserved