iOS 15 导航栏

iOS 15 Navigation Bar

我在使用 SwiftUI 中的导航栏时遇到了这个问题,我不希望第二个视图具有 ContentView 的导航栏。 SecondView 中的预览表现正常,但是一旦我 运行 模拟器并使用 NavigationLink 转到 SecondView,this is what it looks like.

import SwiftUI

struct ContentView: View {
    init() {
        let coloredAppearance = UINavigationBarAppearance()
        coloredAppearance.configureWithTransparentBackground()
        coloredAppearance.backgroundColor = UIColor(
            red: 41/255,
            green: 59/255,
            blue: 77/255,
            alpha: 1)
        coloredAppearance.shadowColor = .clear
        coloredAppearance.titleTextAttributes = [.foregroundColor: UIColor.white]
        coloredAppearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]
        
        UINavigationBar.appearance().standardAppearance = coloredAppearance
        UINavigationBar.appearance().compactAppearance = coloredAppearance
        UINavigationBar.appearance().scrollEdgeAppearance = coloredAppearance
        UINavigationBar.appearance().tintColor = .white
    }
    var body: some View {
        NavigationView {
            NavigationLink(destination: SecondView()) {
                Text("Go to Second View")
                    .navigationTitle("SwiftUI")
            }
        }
    }
}

struct SecondView: View {
    var body: some View {
        NavigationView {
            Text("Second View")
                .navigationBarTitleDisplayMode(.inline)
                .ignoresSafeArea()
        }
        
    }
}
struct SecondView: View {
    var body: some View {
        NavigationView {
            Text("Second View").navigationBarTitle("", displayMode: .inline)
                .navigationBarHidden(true)
        }.navigationBarHidden(true)
    }
}

我已经测试过了,它完全删除了导航栏