当只出现一个视图时如何关闭睡眠?
UIApplication.shared.isIdleTimerDisabled = true 阻止屏幕在每个视图上进入睡眠状态。
如何只是在 ContentView ?
struct ContentView: View {
UIApplication.shared.isIdleTimerDisabled = true
}
Run Code Online (Sandbox Code Playgroud)
使用onAppear和onDisappear:
var body: some View {
Text("Hi there")
.onAppear { UIApplication.shared.isIdleTimerDisabled = true }
.onDisappear { UIApplication.shared.isIdleTimerDisabled = false }
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1062 次 |
| 最近记录: |