首页 > 解决方案 > 动态关闭工作表错误后无法单击 NavigationBarItems?

问题描述

我有 NavigationView 和 NavigationBarItems 按钮。Button 调用一个工作表,我通常可以通过向下拖动来关闭该工作表,然后通过单击一个按钮再次打开该工作表。

问题:如果我在工作表内单击按钮退出面板,则无法再单击面板上的按钮。

struct ContentView: View {

    @State private var showSheet = false

    var body: some View {
        NavigationView {
            Text("Hello World")
                .navigationBarTitle("Mapp")
                .navigationBarItems(trailing: Button(action: showSheetFunc) {
                        Image(systemName: "plus").padding(5)
                })
                .sheet(isPresented: $showSheet) {
                    SheetView(showSheet: self.$showSheet)
            }
        }

    }

    private func showSheetFunc() {
        self.showSheet = true
    }
}

struct SheetView: View {
    @Binding var showSheet: Bool

    var body: some View {
        Button(action: { self.showSheet = false}) {
            Text("Close Me")
        }
    }
}

我制作了一个视频来说明这个问题。最后,当我单击按钮时,什么也没有发生。

https://streamable.com/tza9v4

标签: swiftswiftui

解决方案


为您的按钮图像添加更多填充,例如:

Image(systemName: "plus").padding(20)

推荐阅读