繁体   English   中英

SwiftUI - iOS 14.5 更新导航栏问题

[英]SwiftUI - iOS 14.5 Update navigation bar issue

我将我的应用程序更新为 iOS 14.5,突然出现导航问题。 我在 iOS 14.4 或更低版本中没有这个问题。

我做了一个小的新程序来显示这个问题。 当我单击 navigationLink(不向下滚动)时,第二个视图中的导航栏不可见,图片将显示在顶部。 当我向下滚动一点时,导航栏在第二个视图的顶部直接可见。 如何在不直接在顶部显示导航栏的情况下移至第二个视图? 它应该只在我向下滚动时可见。

请问你能给我一个帮助吗?

提前致谢!

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()
                }
            }
        }
    }
}

图片:显示导航问题

我添加了两张图片: 第一张:父视图 - 没有弹出导航栏。 第二个:父视图-导航栏弹出(向下滚动)。 我喜欢总是只有汽车图片在顶部(在边缘),当你向下滚动时,导航栏就会出现。

[导航栏问题][1] 在此处输入图像描述

问题是navigationbarIssue认为它应该有一个Large Title 风格的导航栏,在滚动之前它是透明的。 您想添加.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!
    }
}

结果:

导航栏停留在推送的导航栏问题视图中

我添加了两张图片: 第一张:父视图 - 没有弹出导航栏。 第二个:父视图-导航栏弹出(向下滚动)。 我喜欢总是只有汽车图片在顶部(在边缘),当你向下滚动时,导航栏就会出现。

[导航栏问题][1] 在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM