如何使用SwiftUI显示全栈模式? [英] How to display a fullstack modal with 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屋!