[英]Extra elements for SwiftUI destination view
Can someone explain why there are 2 UI elements(UINavigationBarContentView, UINavigationBarLargeTitleView) between the Image(the blue rectangle) and navigation bar title(text One )?有人可以解释为什么 Image(蓝色矩形)和导航栏标题(文本One )之间有 2 个 UI 元素(UINavigationBarContentView、UINavigationBarLargeTitleView)吗?
The code I use is this:我使用的代码是这样的:
let item: ImageNameModel
@State private var image: Image?
var body: some View {
NavigationView {
VStack {
if image != nil {
image?.resizable().scaledToFit()
} else {
Text("Image not loaded")
}
}
.padding([.horizontal, .bottom])
}
.navigationBarTitle(Text(item.name))
.onAppear(perform: loadImage)
}
It's probably because of the extra NavigationView.这可能是因为额外的 NavigationView。
You don't need to have a NavigationView
wrapping your destination.您不需要一个
NavigationView
包装您的目的地。
For example, with this sample code here:例如,这里的示例代码:
struct RootView: View {
var body: some View {
NavigationView {
NavigationLink(destination: DestinationView()) {
Text("Click here")
}.navigationBarTitle(Text("Title"))
}
}
}
struct DestinationView: View {
var body: some View {
NavigationView {
Text("Destination")
.navigationBarTitle(Text("Destination"))
}
}
}
I get a result like this:我得到这样的结果:
But If I remove the NavigationView
from DestinationView
, I get the result that is probably what you expect:但是如果我从
DestinationView
中删除NavigationView
,我得到的结果可能是您所期望的:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.