簡體   English   中英

如何在 SwiftUI 的特定屏幕中隱藏標簽欄?

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

如何在特定屏幕中隱藏 tabBar? 我正在從登錄直接導航到 tabBar。 有什么辦法可以隱藏嗎? 在 UIKit 中,我們通過推送來隱藏,我不知道如何在 SwiftUI 中通過呈現視圖不起作用。

這是我的標簽欄

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

我想在這個視圖中隱藏 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()
    }
}

嘗試這個:

// 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