Swiftui NavigationView:删除空格时保持返回按钮
白空间的屏幕截图 我想在第二导航视图中删除<后按钮下方的空空间。我知道这个问题以前已经问过几次,但是我找不到这样做的好解决方案。
我尝试过
.navigationBarTitle("")
.navigationBarHidden(true)
,
.navigationBarTitle("", displayMode: .inline)
没有预期的结果。
有任何提示可以帮助我吗?
struct SecondNavView: View {
let item: String
var body: some View {
ZStack {
Color.red
Text(item)
}
}
}
struct FirstNavView: View {
let listItems = ["One", "Two", "Three"]
var body: some View {
NavigationView {
List(listItems, id: \.self) { item in
NavigationLink(destination: SecondNavView(item: item)) {
Text(item).font(.headline)
}
}
}
}
}
Screen shot of white space
I want to remove the empty space below the <Back button in the second navigation view. I know that this question has been asked several times before, but I have not been able to find a good solution that does this.
I have tried
.navigationBarTitle("")
.navigationBarHidden(true)
and
.navigationBarTitle("", displayMode: .inline)
without the desired result.
Any hints that could help me?
struct SecondNavView: View {
let item: String
var body: some View {
ZStack {
Color.red
Text(item)
}
}
}
struct FirstNavView: View {
let listItems = ["One", "Two", "Three"]
var body: some View {
NavigationView {
List(listItems, id: \.self) { item in
NavigationLink(destination: SecondNavView(item: item)) {
Text(item).font(.headline)
}
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这是对应用的修饰符的位置。
以下工作(用Xcode 13.4/ios 15.5进行测试)
I assume it is do to place of applied modifiers.
The following works (tested with Xcode 13.4 / iOS 15.5)
它像您的父视图一样没有标题,要解决此问题。
It seens like your parent View hasn't a title, to solve this you need to set
.navigationTitle
insideNavigationView
on parent View like this: