我正在尝试实现从导航视图链接的详细视图。在此详细视图中,顶部有一个带有后退按钮的默认导航栏。 但当我向上滚动时,该栏仅显示一些颜色。我不知道为什么。
最初,导航栏在滚动或不滚动时都没有背景。所以我创建了一个 init() 方法来设置样式。
init(fruit: Fruit) {
self.fruit = fruit
if #available(iOS 15.0, *) {
let navigationBarAppearance = UINavigationBarAppearance()
navigationBarAppearance.configureWithDefaultBackground()
UINavigationBar.appearance().standardAppearance = navigationBarAppearance
UINavigationBar.appearance().compactAppearance = navigationBarAppearance
UINavigationBar.appearance().scrollEdgeAppearance = navigationBarAppearance
}
}
Run Code Online (Sandbox Code Playgroud)
主体视图是外部的导航视图和内部的滚动视图。** 对于任何人来说,为什么我将导航栏设置为隐藏在 VStack 中,是因为如果我不隐藏它,图像上方将会有一些巨大的空间。(我不知道为什么)

** 更新的代码 ** 我更新了使用不透明背景的代码。但似乎这些配置都不可见。
init(fruit: Fruit) {
self.fruit = fruit
let navBarAppearance = UINavigationBarAppearance()
navBarAppearance.configureWithOpaqueBackground()
UINavigationBar.appearance().scrollEdgeAppearance = navBarAppearance
UINavigationBar.appearance().standardAppearance = navBarAppearance
}
var body: some View {
NavigationView {
ScrollView(.vertical, showsIndicators: false) {
VStack(alignment: .center, spacing: 20) {
// HEADER
FruitHeaderView(fruit: …Run Code Online (Sandbox Code Playgroud)