【问题标题】:Why does the navigation title display mode change from large to inline when popped in iOS 16?为什么iOS 16弹出时导航标题显示模式由大改为内联?
【发布时间】: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


    【解决方案1】:

    我在 Xcode 13 中使用 Navigation View 实现了您的代码,并且运行良好。这可能是您的 Xcode 或 Navigation Stack 的实现问题

    【讨论】:

    • NavigationView 现在已弃用。 Apple 在他们的文档中声明它here
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-12
    • 1970-01-01
    • 2019-11-01
    • 1970-01-01
    • 2021-06-24
    • 1970-01-01
    • 2018-05-03
    相关资源
    最近更新 更多