如何使用 SwiftUI 显示全栈模式? [英] How to display a fullstack modal with SwiftUI?

查看:21
本文介绍了如何使用 SwiftUI 显示全栈模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个导航栏,底部有一个标签栏,用于我的应用程序中的大部分导航.我试图在单击按钮时显示全屏视图,有效地删除所有导航.

I have a navbar up to and a tab bar at the bottom for most of the navigation in my app. I'm trying to display a fullscreen view, effectively removing all navigation, when clicking a button.

关于 SO 的其他问题在没有导航栏或标签栏时解决了这种情况,因此它们并没有真正回答我的用例.

Other questions on SO address this case when there is no navbar or no tab bar, so they don't really answer my use case.

这是我尝试过的:

  • 隐藏导航栏 &单击选项卡栏:不适用于选项卡栏.如果我在关闭全屏视图时尝试返回另一个视图,顶部导航就会出现问题.

  • Hide the navbar & tab bar on click: doesn't work for the tab bar. The top navigation becomes buggy if I try to go back to another view when dismissing the full screen view.

使用模式:它可以工作,但不是全屏,这不适合我尝试做的事情.

Use a modal: it works, but it's not fullscreen, which doesn't fit what I trying to do.

在我用按钮切换的所有内容之上使用 ZStack:这不会隐藏标签栏.

Use a ZStack on top of everything that I toggle with a button: this doesn't hide the tabbar.

是否有解决方案,或者我应该放弃并使用模态?

Is there a solution, or should I just give up and use a modal?

谢谢

推荐答案

这里是可能的解决方案的演示.

Here is a demo of possible solution.

struct DemoModalOverTabView: View {
    @State private var showModally = false
    var body: some View {
        ZStack {
            TabView {     //  << main tab view
                DemoTab
            }.disabled(showModally) // << deactivate forcefully

            if showModally {
                DemoModal     //  << modal view
                   .zIndex(1)     // << required !!
                   .transition(.move(edge: .bottom)).animation(.default)
            }
        }
    }

    var DemoTab: some View {
        Button("Show") { self.showModally = true }
            .tabItem { Image(systemName: "person") }
    }

    var DemoModal: some View {
        Button("Hide") { self.showModally = false }
           .frame(maxWidth: .infinity, maxHeight: .infinity)
           .background(Color.yellow)
           .edgesIgnoringSafeArea(.all)
    }
}

这篇关于如何使用 SwiftUI 显示全栈模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆