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

时间:2020-01-13 00:51:14

标签: ios swift swiftui ios-navigationview

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

我有以下屏幕:

主要

<!-- **** launch container ****** -->
<section class="launch-container">
  <div class="launch container-item">
  </div>

  <div class="launch-activities container-item">
  </div>

  <div class="calling container-item">
  </div>

  <div class="script container-item">
  </div>

</section>

首页

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

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

1 个答案:

答案 0 :(得分:0)

当我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
    }
}