如何在SwiftUI中隐藏NavigationView Bar

Boh*_*ych 3 ios swift swift5 swiftui

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

代码1:

  public var body: some View {
    NavigationView {
      MasterView()
        .navigationBarHidden(true)
    }
  }
Run Code Online (Sandbox Code Playgroud)

代码2:

  public var body: some View {
    NavigationView {
      MasterView()
    }
      .navigationBarHidden(true)
  }
Run Code Online (Sandbox Code Playgroud)

有谁知道如何解决它?

Giu*_*nza 13

Seems that the solution could be adding a title or removing the space from safe area.

The problem:

在此处输入图片说明

Solution 1:

.navigationBarHidden(true)
.navigationBarTitle(Text("Home"))
Run Code Online (Sandbox Code Playgroud)

Solution 2 (this seems be the best):

.navigationBarHidden(true)
.navigationBarTitle(Text("Home"))
.edgesIgnoringSafeArea([.top, .bottom])
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

  • 在 iOS 14 中,使用 .navigationBarHidden(true) 就可以完成这项工作。 (4认同)
  • 不适用于 iOS 15 (4认同)
  • 奇怪的是,我们需要设置一个标题来隐藏它......但是有效,谢谢。 (2认同)