12

我想呈现模态视图,并在解雇后再次呈现它。

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什么也不做。有人有解决方案吗?

4

1 回答 1

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)
    }
}
于 2019-06-11T07:33:16.063 回答