ios - Xcode Beta 6 中的 SwiftUI 模式?

标签 ios swift xcode swiftui xcode11

以前在 SwiftUI(Xcode Beta 5)中,模态是这样工作的:

struct ContentView: View {

    @State var modalIsPresented: Bool = false

    var body: some View {

        Button(action: {

            self.modalIsPresented = true

        }) {

            Text("Show modal")

        }

        .sheet(isPresented: $modalIsPresented, content: {

            ModalView()

        })

    }

}

struct ModalView: View {

    @Environment(\.presentationMode) var presentationMode

    var body: some View {

        Button(action: {

            self.presentationMode.value.dismiss()

        }) {

            Text("Hide modal")

        }

    }

}

但是现在在 Xcode Beta 6 中,我找不到关闭模态的方法。 presentationMode 不再有 value 属性,其他属性似乎也没有任何我可以使用的有用方法。

如何在 Xcode Beta 6 中关闭 SwiftUI 模态?

最佳答案

使用 wrappedValue 而不是 value 似乎在 Xcode Beta 6 中有效:

self.presentationMode.wrappedValue.dismiss()

关于ios - Xcode Beta 6 中的 SwiftUI 模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57622486/

相关文章:

ios - Keychain 和 Secure Enclave 之间有什么区别

ios - 在 Xcode 中查看 TestFlight 崩溃日志

ios - Xcode-Maven-Plugin 是否可以在 PC 上构建 iOS 应用程序

ios - 如何在不重复代码的情况下在 Swift 中实现两个具有相同内容的 init?

Objective-C setFrame Swift 等效项

ios - 构建具有多个目标的框架

iphone - iOS 可以批量发送短信吗?

iphone - xlsx 数据库 ios

ios - iPhone、iPod touch、iPad 发展差异

ios - 尝试在后台上传时 NSURLSessionUploadTask 崩溃