20

I cannot hide NavigationView bar. I tried both variants:

Code 1:

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

Code 2:

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

Does anyone have an idea how to fix it?

Giuseppe Sapienza
  • 4,101
  • 22
  • 23
Bohdan Savych
  • 3,310
  • 4
  • 28
  • 47

2 Answers2

53

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

The problem:

enter image description here

Solution 1:

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

Solution 2 (this seems be the best):

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

enter image description here

Giuseppe Sapienza
  • 4,101
  • 22
  • 23
0

navigationBarHidden will be deprecated in a future.

Solution:

struct HiddenNavUIView: View {
  @State private var tabState: Visibility = .hidden
  
  var body: some View {
      NavigationStack {
        ScrollView {
          VStack(spacing: 12) {
            ForEach(1...50, id: \.self) { index in
              Text("Row \(index)")
              .frame(height: 32)
            }
          }
          .padding(15)
        }
        .navigationTitle("Hello")
        .toolbar(tabState, for: .navigationBar) // <- here
      }
  }
}
Viet Hung Do
  • 16
  • 1
  • 4