简体   繁体   English

"如何在 ProgressView 显示时禁用交互(SwiftUI)"

[英]How to disable interaction while ProgressView showing (SwiftUI)

I have a view with structure like this:我有这样的结构视图:

struct ContentView: View {
    @ObservedObject private var viewModel = MyViewModel()
    
    var body: some View {
        ZStack {
            VStack {
                // Several buttons and input forms
            }

            // the viewModel has published states. 
            switch viewModel.state {
                case .loading:
                    ProgressView()
                case .finish:
                    // ...
                case .error:
                    // ...
            }
        }
    }
}

What I want to achieve is to simply avoid user interacting with any other components if the ProgressView appeared, but couldn't find a good way...我想要实现的是在ProgressView出现时简单地避免用户与任何其他组件交互,但找不到好方法......

You can use the .disabled<\/code> modifier on your controls.您可以在控件上使用.disabled<\/code>修饰符。

For example:例如:

Button("Button") { //action }.disabled(isLoading)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM