本文介绍了SwiftUI UIApplication.shared.isIdleTimerDisabled = true 仅在一个视图上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当只出现一个视图时如何关闭睡眠?

How can i turn Sleep off when just one View is Appeared ?

UIApplication.shared.isIdleTimerDisabled = true 阻止屏幕在每个视图上进入睡眠状态.

UIApplication.shared.isIdleTimerDisabled = true stop the screen from going to sleep on every View.

如何在 ContentView 中?

how just in ContentView ?

struct ContentView: View {
  UIApplication.shared.isIdleTimerDisabled = true


}

推荐答案

使用onAppearonDisappear:

var body: some View {
    Text("Hi there")
        .onAppear { UIApplication.shared.isIdleTimerDisabled = true }
        .onDisappear { UIApplication.shared.isIdleTimerDisabled = false }
}

这篇关于SwiftUI UIApplication.shared.isIdleTimerDisabled = true 仅在一个视图上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 19:51