我有三个视图,我想在第三个视图中隐藏导航栏。即使我使用 .navigationBarHidden(true)
,导航栏仍然显示!
我找不到我的错误所在。下面是我的代码和结果截图。
Xcode 版本 - 11.1
struct ContentViewOne: View {
var body: some View {
NavigationView {
ZStack {
Color.yellow.edgesIgnoringSafeArea(.all)
VStack(spacing: 20) {
Text("View One")
NavigationLink(destination: ContentViewTwo()) {
Text("Navigate to View Two")
.foregroundColor(.white)
.padding()
.background(Color.red)
}
}
}
.navigationBarTitle("View One")
}
}
}
struct ContentViewTwo: View {
var body: some View {
ZStack {
Color.green.edgesIgnoringSafeArea(.all)
VStack(spacing: 20) {
Text("View Two")
NavigationLink(destination: ContentViewThree()) {
Text("Navigate to View Three")
.foregroundColor(.white)
.padding()
.background(Color.red)
}
}
}
.navigationBarTitle("View Two")
}
}
struct ContentViewThree: View {
var body: some View {
ZStack {
Color.gray.edgesIgnoringSafeArea(.all)
Text("View Three")
}
.navigationBarTitle("View Three")
.navigationBarHidden(true)
.navigationBarBackButtonHidden(true)
}
}