簡體   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