仅显示一个视图时如何关闭睡眠?
UIApplication.shared.isIdleTimerDisabled = true阻止屏幕在每个View上进入休眠状态。
在ContentView中怎么样?
synchronized
答案 0 :(得分:1)
使用onAppear
和onDisappear
:
var body: some View {
Text("Hi there")
.onAppear { UIApplication.shared.isIdleTimerDisabled = true }
.onDisappear { UIApplication.shared.isIdleTimerDisabled = false }
}