以前在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中,我找不到消除模态的方法。不再具有的value
属性presentationMode
,而其他属性似乎没有可用的任何有用方法。
如何在Xcode Beta 6中关闭SwiftUI模式?
在Xcode Beta 6中,使用wrappedValue代替值似乎可以:
self.presentationMode.wrappedValue.dismiss()