TreatTrick / Hide-TabBar-In-SwiftUI

This tutorial provides a solution to hide TabBars when using TabView in SwiftUI
185 stars 14 forks source link

I found another way! #5

Open woozoobro opened 1 year ago

woozoobro commented 1 year ago

TabBarCustom

There's a .toolbar(.hidden, for: .tabBar) modifier.

Put this modifier in the destination View.

And then

In the ContentView

struct ContentView: View {
    @State private var selection: Int = 0

    var body: some View {

        TabView(selection: $selection) {
            HomeView()
            .tabItem {
                Image(systemName: "house")
            }
            .toolbarBackground(.visible, for: .tabBar)
            .tag(0)

            NavigationStack {
                ForumView()
            }
            .tabItem {
                Image(systemName: "text.bubble")
            }
            .toolbarBackground(.visible, for: .tabBar)
            .tag(1)

            NavigationStack {
                ProjectsView()
            }
            .tabItem {
                Image(systemName: "folder.fill")
            }
            .toolbarBackground(.visible, for: .tabBar)
            .tag(2)

            LoginRootView()
            .tabItem {
                Image(systemName: "person.crop.circle")
            }
            .toolbarBackground(.visible, for: .tabBar)
            .tag(3)
        }
        .tint(Color.orange)
        .animation(.spring(response: 0.3, dampingFraction: 0.6), value: selection)
        .toolbar(.visible, for: .tabBar)        
    }

.animation(.spring(response: 0.3, dampingFraction: 0.6), value: selection)

Put this animation in the TabView's selection property

TreatTrick commented 1 year ago

Thanks very much for giving this important feedback to this project. I am sorry because I have not focused on iOS development for years and didn't reply your last question immediately.

cairongquan commented 3 months ago

hi,is support ios15