如何在SwiftUI中隐藏NavigationView Bar

时间:2019-08-01 13:20:04

标签: ios swift swiftui swift5

我无法隐藏NavigationView栏。我尝试了两种变体:

代码1:

  public var body: some View {
    NavigationView {
      MasterView()
        .navigationBarHidden(true)
    }
  }

代码2:

  public var body: some View {
    NavigationView {
      MasterView()
    }
      .navigationBarHidden(true)
  }

有人知道如何解决吗?

1 个答案:

答案 0 :(得分:17)

似乎解决方案可能是添加标题或从安全区域删除空格。

问题:

enter image description here

解决方案1:

.navigationBarHidden(true)
.navigationBarTitle(Text("Home"))

解决方案2(这似乎是最好的):

.navigationBarHidden(true)
.navigationBarTitle(Text("Home"))
.edgesIgnoringSafeArea([.top, .bottom])

enter image description here