我想呈现模态视图,并在关闭后再次呈现它。
struct ContentView : View {
var body: some View {
NavigationView {
Group {
Text("hi")
Text("hello")
}
.navigationBarItem(title: Text("Demo"))
.navigationBarItems(trailing:
PresentationButton(
Image(systemName: "person.crop.circle")
.imageScale(.large)
.accessibility(label: Text("User Profile"))
.padding(),
destination: Text("User Profile")
)
)
}
}
}
仅在第一次点击时触发。取消目标视图后,点击PresentationButton
不会执行任何操作。有人对此有解决方案吗?
答案 0 :(得分:5)
它看起来像个错误,这是一种解决方法:
struct ContentView : View {
@State var showModal: Bool = false
var body: some View {
NavigationView {
Group {
Text("hi")
Text("hello")
}
.navigationBarItem(title: Text("Demo"))
.navigationBarItems(trailing:
Button(action: {
self.showModal = true
}) {
Image(systemName: "person.crop.circle")
}
)
}.presentation(showModal ? Modal(Text("Hey"),
onDismiss: { self.showModal = false }) : nil)
}
}