导航栏隐藏在 SwiftUI 中不起作用 [英] Navigation Bar hide is not working in SwiftUI
本文介绍了导航栏隐藏在 SwiftUI 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有三个视图.我想隐藏第三个视图中的导航栏.即使我给 .navigationBarHidden(true)
导航栏正在显示!
I'm having Three Views. I want to hide the navigation bar in the third View. Even if I give .navigationBarHidden(true)
the navigation bar is displaying!
我找不到我做错的地方.我附上了我的代码和下面的截图.
I couldn't find where I'm doing wrong. I've attached my code and the resulting screenshot below.
Xcode 版本 - 11.1
Xcode version - 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)
}
}
推荐答案
注意:(出于某种原因它在某些情况下有效)SwiftUI
要求您需要 .navigationBarTitle
使 .navigationBarHidden
正常工作.
NOTE: (For some reason it works in some cases) SwiftUI
requires that you need to .navigationBarTitle
for .navigationBarHidden
to work properly.
NavigationView {
ScrollView() {
......
}.
.navigationBarTitle("") //this must be empty
.navigationBarHidden(true)
.navigationBarBackButtonHidden(true)
}
这篇关于导航栏隐藏在 SwiftUI 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文