我有一个用于摄影目的(类似灯箱)的iPhone应用程序。这个应用程序需要尽可能多的亮度。是否有一种方法可以通过编程方式改变屏幕亮度,然后在一段时间后恢复它?
编辑:iOS 5现在包括一个屏幕亮度 API。
[[UIScreen mainScreen] setBrightness:0.5];
之前的回答:
不,这种功能无法通过公共API公开。
编辑:请注意,未来可能发布的某个iOS版本可能会在一个特定的iDevice上在多任务栏中显示屏幕亮度或可能不会显示。
import UIKit
extension UIScreen
{
static func setMainBrightness(brightness: CGFloat)
{
guard (0...1).contains(brightness) else
{
print("Attempt to set the screen brightness to an invalid value: \(brightness) should be between 0 and 1 inclusive.")
return
}
self.main.brightness = brightness
}
}
通过以下方式来调用:
UIScreen.setMainBrightness(0.5)
或者忽略我的扩展(我只是为了说明限制而编写的),直接调用:
UIScreen.main.brightness = 0.5
UIScreen.main.brightness = 1.0
- bshirley