Reputation: 3457
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?
Upvotes: 21
Views: 26012
Reputation: 36
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
}
}
}
Upvotes: 2
Reputation: 4708
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"))
Solution 2 (this seems be the best):
.navigationBarHidden(true)
.navigationBarTitle(Text("Home"))
.edgesIgnoringSafeArea([.top, .bottom])
Upvotes: 57