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

能否通过Apple内置Sheet实现全屏NavigationStack视图跳转?

从Sheet内实现全屏导航的可行方案

你要的这种交互完全能用Apple原生Sheet实现,核心是换一种视图触发方式,而不是死磕navigationDestination:

最优实现方式:用fullScreenCover触发全屏视图

直接在Sheet的内容视图里通过fullScreenCover来弹出全屏新视图,关闭后会自动回到原Sheet,和Instagram、TikTok的逻辑完全一致:

struct ContentView: View {
    @State private var showSheet = false
    @State private var showFullScreenView = false
    
    var body: some View {
        Button("打开评论Sheet") {
            showSheet = true
        }
        .sheet(isPresented: $showSheet) {
            CommentSheetContent(showFullScreenView: $showFullScreenView)
        }
    }
}

struct CommentSheetContent: View {
    @Binding var showFullScreenView: Bool
    
    var body: some View {
        VStack {
            Button("查看用户资料") {
                showFullScreenView = true
            }
        }
        .fullScreenCover(isPresented: $showFullScreenView) {
            UserProfileView()
        }
    }
}

struct UserProfileView: View {
    @Environment(\.dismiss) private var dismiss
    
    var body: some View {
        VStack {
            Text("用户资料页")
            Button("返回评论Sheet") {
                dismiss()
            }
        }
        .frame(maxWidth: .infinity, maxHeight: .infinity)
        .background(.white)
    }
}

备选方案:基于导航栈的全屏布局

如果需要保留导航栏交互,可以把Sheet内容嵌入NavigationStack,同时让目标视图占满全屏:

struct CommentSheetContent: View {
    @State private var navigateToProfile = false
    
    var body: some View {
        NavigationStack {
            VStack {
                Button("查看用户资料") {
                    navigateToProfile = true
                }
            }
            .navigationDestination(isPresented: $navigateToProfile) {
                UserProfileView()
                    .frame(maxWidth: .infinity, maxHeight: .infinity)
                    .background(.white)
                    .navigationBarBackButtonHidden()
            }
        }
    }
}

这种方式下,新视图会铺满整个屏幕,关闭后回到Sheet的导航栈中,同样能满足需求。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 19:13:13