简体   繁体   English

如何在 SwiftUI 的特定屏幕中隐藏标签栏?

[英]how can I hide tab bar in specific screens in SwiftUI?

How to hide the tabBar in specific screens?如何在特定屏幕中隐藏 tabBar? I'm navigating from login to directly to tabBar.我正在从登录直接导航到 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.在 UIKit 中,我们通过推送来隐藏,我不知道如何在 SwiftUI 中通过呈现视图不起作用。

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我想在这个视图中隐藏 tabBar

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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