admin管理员组文章数量:1125015
One of the screens in my app shows a barcode. When a user navigates to the screen (it is a tab in my tabview) I set the screen brightness to the maximum. When a user navigates away from the screen I restore the screen brightness to what it was. The brightness isn't restored when the user closes the app, either by moving it to the background or closing it completely. How can I restore the screen brightness when a user closes the app?
struct BarcodeView: View {
@Environment(\.scenePhase) var scenePhase
@State private var originalBrightness: CGFloat = 0.0
var body: some View {
Barcode()
.onAppear {
originalBrightness = UIScreen.main.brightness
UIScreen.main.brightness = 1.0
}
.onDisappear {
UIScreen.main.brightness = originalBrightness
}
.onChange(of: scenePhase) { _, newPhase in
if newPhase == .background {
UIScreen.main.brightness = originalBrightness
}
}
}
}
The .onDisappear
and .onChange
modifiers trigger when the app moves to the background or is closed, but the brightness is unchanged. From google I understand that this is intended behaviour, apps shouldn't be able to change the brightness settings when they aren't active, which makes sense. Is there a way to restore the original screen brightness or is this not possible?
本文标签: swiftuiHow to restore screen brightness when closing iOS appStack Overflow
版权声明:本文标题:swiftui - How to restore screen brightness when closing iOS app - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736654884a1946227.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论