【发布时间】:2022-10-06 11:33:20
【问题描述】:
当我从具有内联显示模式的推送视图中弹出时,最初很大的父视图的显示模式更改为内联,并且用户必须向下滚动才能使标题恢复到其原始模式。
问:如何确保设置视图上的大标题始终显示?
我正在使用 Xcode 14 beta 6 并且在预览中它不会发生但是在运行 iOS 16 的模拟器上它会发生。
设置视图
struct SettingsView: View {
@State private var isPresentingChangePasswordView = false
var body: some View {
Form {
Section {
NavigationLink(destination: EmptyView()) {
Label(\"Account Details\", systemImage: \"person\")
}
NavigationLink {
Form {
Button(\"Change Password\") {
isPresentingChangePasswordView = true
}
}
.navigationTitle(\"Password & Security\")
.navigationBarTitleDisplayMode(.inline)
} label: {
Label(\"Password & Security\", systemImage: \"lock\")
}
NavigationLink(destination: EmptyView()) {
Label(\"Manage Subscription\", systemImage: \"crown\")
}
Button {
} label: {
HStack {
Label {
Text(\"Sign Out\")
.foregroundColor(.black)
} icon: {
Image(systemName: \"rectangle.portrait.and.arrow.right\")
}
Spacer()
Image(systemName: \"chevron.forward\")
.foregroundColor(Color(red: 191/255, green: 191/255, blue: 191/255))
.fontWeight(.semibold)
.imageScale(.small)
}
}
} header: {
Text(\"Your account\")
}
}
.navigationTitle(\"Settings\")
.navigationBarTitleDisplayMode(.large)
.sheet(isPresented: $isPresentingChangePasswordView) {
ChangePasswordView()
}
}
}
主页查看
struct HomeView: View {
var body: some View {
NavigationStack {
Text(\"HomeView\")
.toolbar {
NavigationLink(destination: SettingsView()) {
Image(systemName: \"gearshape\")
.foregroundColor(.gray)
}
}
.navigationTitle(\"Home\")
}
}
}
更新#1
当用 NavigationView 替换 NavigationStack 时,它完全按照我想要的方式工作。虽然这是我正在寻找的东西,但我不会认为它是答案,因为 Apple 已经宣布了 NavigationView will deprecated as of iOS 16。
标签: swift swiftui swiftui-navigationview ios16 swiftui-navigationstack