SwiftUI:在特定屏幕上隐藏导航栏

SwiftUI: Hide Navigation Bar on Specific Screens

我似乎无法选择要在 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)
    }
}

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

正如我 saw earlier,当您同时使用两者时出现问题:

.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
    }
}