ios - 导航栏隐藏在 SwiftUI 中不起作用
问题描述
我有三观。我想在第三个视图中隐藏导航栏。即使我给.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)
}
}
解决方案
注意:(由于某些原因,它在某些情况下有效)SwiftUI
需要您.navigationBarTitle
才能.navigationBarHidden
正常工作。
NavigationView {
ScrollView() {
......
}.
.navigationBarTitle("") //this must be empty
.navigationBarHidden(true)
.navigationBarBackButtonHidden(true)
}
推荐阅读
- c# - 浮动/双发行 x64/x86
- node.js - Nodejs mongodb驱动程序在客户端关闭时挂起
- python - Tkinter 滚动条未正确填充或对齐
- java - Spring Neo4j:如何使用带有过滤器的枚举
- docker - Tensorboard 无效响应:Jupyterlab 中的 500 内部服务器错误
- javascript - 单击按钮从 firebase 实时数据库中删除条目
- c++ - 如何在 C++ 中创建元组向量?
- c++ - H5Tget_member_type() 返回复合 HDF5 数据类型的奇怪值
- sql - 我们可以在 sql server 中对 CTE 表使用两个不同的查询吗
- json - 使用 DynamoDB 属性名称通过 REST 发送 JSON