简体   繁体   中英

how can I hide tab bar in specific screens in SwiftUI?

How to hide the tabBar in specific screens? I'm navigating from login to directly to tabBar. Is there any way to hide? In UIKit we're hiding by pushing and I have no idea how to do it in SwiftUI, by presenting the view not going to work.

Here is my TabBar

struct ReceiverTabBar: View {
    @State private var selection: Int = 0
  
    var body: some View {
        TabView(selection: $selection){
                .tabItem {
                    selection == 0 ? Image("")
                    Text("")
                }
                .tag(0)
            
            ReceiverProfileView()
                .tabItem {
                    selection == 1 ? Image("")
                    Text("")
                }
                .tag(1)
            ReceiverNotificationsView()
                .tabItem {
                    selection == 2 ? Image("")
                    Text("")
                }
                .tag(2)
            ReceiverMoreView()
                .tabItem {
                    selection == 3 ? Image("")
                    Text("")
                }
                .tag(3)
        }
        .accentColor(.black)
    }
}

and I want hide tabBar in this view

struct MakingDonationView: View {
    
    @Environment(\.presentationMode) var presentationMode
    @State var selected = 0
    
    var body: some View {
        
                ScrollView(showsIndicators: false) {
                            Image("")
                                .resizable()
                                .aspectRatio(contentMode: .fit)
                                .padding(.horizontal,30)
                                .padding(.top,40)
                                .frame(height: UIScreen.main.bounds.height/5)
                            
                                Text("")
                                    .font(.custom("Poppins-SemiBold", size: 16))
                                    .foregroundColor(Color("#252422"))
                                    .padding(.top,20)
                                
                                
                                Text("")
                                    .font(.custom("Poppins-SemiBold", size: 12))
                                    .foregroundColor(Color("#5E5E5E"))
                                
                                Text("")
                                    .font(.custom("Poppins-Medium", size: 12))
                                    .foregroundColor(Color("#A0A0A0"))
                            }
                            Spacer()
                            Divider()
                            
                            MakingDonation(selected: $selected)
                                
                        }
                        .padding(.all)
                        
                    }
                    .padding(.horizontal,20)
                    .edgesIgnoringSafeArea(.bottom)
                }
                        Button(action: {
                        }, label: {
                            
                            Spacer()
                            Text("Confirm Donation Amount")
                                .font(.custom("Poppins-SemiBold", size: 13))
                                .foregroundColor(.black)
                            Spacer()
                        })
                        .frame(height:44)
                        .background(Color("#FFA919"))
                        .padding(.horizontal,20)
                    }
                    .shadow(color: .gray, radius: 1, x: 0, y: 2)
                    .cornerRadius(4)
                    
                }
                .shadow(color: .gray, radius: 2, x: 0, y: 2)
                .edgesIgnoringSafeArea(.all)
                .frame(height:80)
                
                .navigationBarBackButtonHidden(true)
                .navigationBarTitle("Making Donation", displayMode: .inline)
            }
    }
    func goBack(){
        self.presentationMode.wrappedValue.dismiss()
    }
}

Try this:

// Container Screen view for handling all screen
struct ContainerView: View {
    @State var tabSelection: Screens = .screen1
    var body: some View {
        NavigationView{
            TabView(selection: $tabSelection){
                // Screen 1
                // Hide tab bar view only for Screen 1 
                NavigationLink(destination: PushedView()){
                    VStack{
                        Text("Screen 1")
                        Text("Tap to PushedView")
                    }
                }
                .tabItem { Text("Screen 1") }
                .tag(Screens.screen1)
                
                // Screen 2
                // same view using for screen 2 for directly shows on that
                PushedView()
                .tabItem { Text("Screen 2") }
                .tag(Screens.screen2)
            }
            .navigationBarTitle( self.tabSelection.title)
        }
    }
}

// New view for pushing
struct PushedView: View {
     var body: some View {
        Text("Hi! This is the new View")
            .navigationBarTitle("NewView")
     }
 }

// Tab screens
enum Screens{
    case screen1, screen2
    
    var title: String {
        switch self {
        case .screen1:
            return "Screen1"
        case .screen2:
            return "Screen2"
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM