Reputation: 11
I setting UIScreen.main.brightness = 1.0
at viewDidLoad.
But print in console value of UIScreen.main.brightness
is 0.9483038187026978.
Please help me. I not good English , so sorry
Upvotes: 0
Views: 408
Reputation: 3031
You can use SceneDelegate as described in the following article:
--
From the article:
We will add a separate class dedicated to controlling the screen brightness:
final class DimUnDim {
static let shared = DimUnDim()
private var originalBrightness = UIScreen.main.brightness
func dim() {
print("dim")
UIScreen.main.wantsSoftwareDimming = true
UIScreen.main.brightness = 0.0
}
func unDim() {
print("unDim")
UIScreen.main.brightness = originalBrightness
}
}
We will call Dim when the app becomes active and call UnDim when the app is not active. Edit the file SceneDelegate.swift and add the following:
func sceneDidBecomeActive(_ scene: UIScene) {
DimUnDim.shared.dim()
}
func sceneWillResignActive(_ scene: UIScene) {
DimUnDim.shared.unDim()
}
Upvotes: -1