[英]SwiftUI - iOS 14.5 Update navigation bar issue
I updated my app to iOS 14.5 and suddenly a navigation problem showed up.我将我的应用程序更新为 iOS 14.5,突然出现导航问题。 I didn't had this issue in iOS 14.4 or lower.
我在 iOS 14.4 或更低版本中没有这个问题。
I made a small new program to show the issue.我做了一个小的新程序来显示这个问题。 When I clicked on the navigationLink (without scrolling down) the navigation bar in the second view isn't visible and the pictures will be shown in the top.
当我单击 navigationLink(不向下滚动)时,第二个视图中的导航栏不可见,图片将显示在顶部。 When I scroll down a little the navigation bar is directly visible in the top of the second view.
当我向下滚动一点时,导航栏在第二个视图的顶部直接可见。 How can I move to the second view without showing the navigation bar directly at the top?
如何在不直接在顶部显示导航栏的情况下移至第二个视图? It should only visible when I scrolling down.
它应该只在我向下滚动时可见。
Please could you give me a help on this?请问你能给我一个帮助吗?
Thanks in advance!提前致谢!
import SwiftUI
struct ContentView: View {
var body: some View {
GeometryReader{ geo in
NavigationView {
VStack{
List {
NavigationLink(destination: navigationbarIssue()){
Text("Navigation image")
}
Image("car")
.resizable().frame(width: geo.size.width * 0.85, height: 600, alignment: .center)
.scaledToFill()
}
Text("Hello, Do you like this mini car!")
.padding()
}
.navigationTitle("Car")
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct navigationbarIssue: View {
var body: some View {
GeometryReader { geo in
ScrollView {
VStack{
Image("car")
.resizable().frame(width: geo.size.width * 1.11, height: geo.size.height * 1.11)
.edgesIgnoringSafeArea([.top, .bottom])
.offset(x: -20, y: -166)
.aspectRatio(contentMode: .fit)
Text("Question: What's the topspeed of this mini car?")
.padding()
}
}
}
}
}
I added two pictures: First one: parent view - without navigationbar pop out.我添加了两张图片: 第一张:父视图 - 没有弹出导航栏。 Second one: parent view - navigationbar pop out (scroll down).
第二个:父视图-导航栏弹出(向下滚动)。 I like to have always only the car picture on the top (on the edge) and when you scroll down the navigationbar appears.
我喜欢总是只有汽车图片在顶部(在边缘),当你向下滚动时,导航栏就会出现。
The problem is that navigationbarIssue
thinks it should have a Large Title style navigation bar, which is transparent until scrolled.问题是
navigationbarIssue
认为它应该有一个Large Title 风格的导航栏,在滚动之前它是透明的。 You want to add .navigationBarTitleDisplayMode(.inline)
so that it has a inline navigation style.您想添加
.navigationBarTitleDisplayMode(.inline)
使其具有内联导航样式。
struct navigationbarIssue: View {
var body: some View {
GeometryReader { geo in
ScrollView {
VStack{
Image("car")
.resizable().frame(width: geo.size.width * 1.11, height: geo.size.height * 1.11)
.edgesIgnoringSafeArea([.top, .bottom])
.offset(x: -20, y: -166)
.aspectRatio(contentMode: .fit)
Text("Question: What's the topspeed of this mini car?")
.padding()
}
}
}
.navigationTitle("The car") /// might want to add a title too
.navigationBarTitleDisplayMode(.inline) /// here!
}
}
Result:结果:
I added two pictures: First one: parent view - without navigationbar pop out.我添加了两张图片: 第一张:父视图 - 没有弹出导航栏。 Second one: parent view - navigationbar pop out (scroll down).
第二个:父视图-导航栏弹出(向下滚动)。 I like to have always only the car picture on the top (on the edge) and when you scroll down the navigationbar appears.
我喜欢总是只有汽车图片在顶部(在边缘),当你向下滚动时,导航栏就会出现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.