Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
799 views
in Technique[技术] by (71.8m points)

ios - 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.

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.

Here what I have tried:

  • 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.

  • 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?

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here is a demo of possible solution.

demo

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)
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...