0

似乎我无法选择要在 swift UI 中隐藏导航栏的页面。

我有以下屏幕:

主要的

struct Main: View {
    var body: some View {
        NavigationView {
                Home()
            }
        }
}

struct Home: View {
    var body: some View {
            NavigationLink(destination: Details()) {
                    Text("Go Next")
            }
        // I expect the navigation bar to show up here, and it does
        .navigationBarTitle("Home")
        .navigationBarHidden(false)
    }
}

细节

struct Details: View {
    @Environment(\.presentationMode) var mode: Binding<PresentationMode>

    var body: some View {
            Button(action: { self.mode.wrappedValue.dismiss() }) {
                Text("Go Back")
            }
        // I expect the navigation bar to be hidden here
        // At first, it is hidden. Then, after a second, it pops up 
        // with the title "Details"
        .navigationBarTitle("Details")
        .navigationBarHidden(true)
    }
}

要么我做错了(可能),要么苹果有一些工作要做(也可能)。

4

1 回答 1

1

正如我之前看到的,当您同时使用这两种方法时,出现了问题:

.navigationBarTitle("some text")
.navigationBarHidden(true)

在下面的代码中,没有导航栏人员,也没有弹出任何内容:

struct Details: View {
    @Environment(\.presentationMode) var mode: Binding<PresentationMode>

    var body: some View {
            Button(action: { self.mode.wrappedValue.dismiss() }) {
                Text("Go Back")
            }
        .navigationBarHidden(true)
        .navigationBarBackButtonHidden(true) // even no back button
    }
}
于 2020-01-13T02:56:52.713 回答