以前在 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/