You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

底部Sheet内NavigationStack标题设.large仍显示为inline的问题求助

解决Sheet内NavigationStack标题默认以Large模式显示的问题

方案1:调整修饰符应用位置

把navigationBarTitleDisplayMode(.large)直接应用到NavigationStack上,而非内部的Form,让导航栈初始就识别大标题模式:

NavigationStack {
    Form {
        // 你的表单内容
    }
    .navigationTitle("Title")
}
.navigationBarTitleDisplayMode(.large)

方案2:手动触发滚动(兼容更多场景)

如果方案1无效,可在Form的onAppear回调里,让滚动视图轻微偏移,触发大标题展开逻辑:

NavigationStack {
    Form {
        // 你的表单内容
    }
    .navigationTitle("Title")
    .navigationBarTitleDisplayMode(.large)
    .onAppear {
        DispatchQueue.main.async {
            // 获取当前表单对应的滚动视图
            guard let scrollView = UIApplication.shared.windows.first?.rootViewController?.presentedViewController?.view.subviews.compactMap({ $0 as? UIScrollView }).first else { return }
            // 轻微偏移触发大标题展开
            scrollView.setContentOffset(CGPoint(x: 0, y: -1), animated: false)
        }
    }
}

方案3:全局设置(不推荐,除非全App需要大标题)

如果你的应用所有页面都默认需要大标题,可在App初始化时设置全局导航栏外观:

@main
struct YourApp: App {
    init() {
        UINavigationBar.appearance().prefersLargeTitles = true
    }
    
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

之后只需在页面设置navigationTitle,无需额外指定显示模式。

内容的提问来源于stack exchange,提问作者helloimbrando

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 00:38:23