Ios 如何隐藏TabBar Swift UI?

Ios 如何隐藏TabBar Swift UI?,ios,xcode,swiftui,Ios,Xcode,Swiftui,我在根视图中有一个TabBarView。在嵌套在根视图中的一个父视图中,我希望在从父视图导航到子视图时隐藏选项卡栏。有任何func或命令来处理这个问题吗 大概是这样的: ContentView(带TabBarView)->ExploreView(在TabBarView中调用)->MessagesView(ExploreView的子级-隐藏选项卡栏) 我的代码可以在下面看到 TabView{ NavigationView{ GeometryReader { geometr

我在根视图中有一个
TabBarView
。在嵌套在根视图中的一个父视图中,我希望在从父视图导航到子视图时隐藏选项卡栏。有任何func或命令来处理这个问题吗

大概是这样的:

ContentView(带TabBarView)->ExploreView(在TabBarView中调用)->MessagesView(ExploreView的子级-隐藏选项卡栏)

我的代码可以在下面看到

TabView{

    NavigationView{
        GeometryReader { geometry in
            ExploreView()
                .navigationBarTitle(Text(""), displayMode: .inline)
                .navigationBarItems(leading: Button(action: {
                }, label: {
                    HStack{
                        Image("cityOption")
                        Text("BER")
                        Image("arrowCities")
                    }.foregroundColor(Color("blackAndWhite"))
                        .font(.system(size: 12, weight: .semibold))
                }),trailing:
                    HStack{
                        Image("closttop")
                            .renderingMode(.template)
                            .padding(.trailing, 125)

                        NavigationLink(destination: MessagesView()
                            .navigationBarTitle(Text("Messages"), displayMode: .inline)
                            .navigationBarItems(trailing: Image("writemessage"))
                            .foregroundColor(Color("blackAndWhite"))
                        ){
                            Image("messages")
                        }
                    }.foregroundColor(Color("blackAndWhite"))
            )
        }
    }
    .tabItem{
        HStack{
            Image("clostNav").renderingMode(.template)
            Text("Explore")
                .font(.system(size: 16, weight: .semibold))
        }.foregroundColor(Color("blackAndWhite"))
    }
    SearchView().tabItem{
        Image("search").renderingMode(.template)
        Text("Search")
    }
    PostView().tabItem{
        HStack{
            Image("post").renderingMode(.template)
                .resizable().frame(width: 35, height: 35)
        }
    }
    OrdersView().tabItem{
        Image("orders").renderingMode(.template)
        Text("Orders")
    }
    ProfileView().tabItem{
        Image("profile").renderingMode(.template)
        Text("Profile")
    }
}

谢谢你的帮助!谢谢

在正常的iphone环境中,如果您正在导航,或者您正在另一个环境中运行,选项卡栏将自动消失

选中此项:

struct ContentView: View {

    @State var hideTabbar = false
    @State var navigate = false

    var body: some View {
        NavigationView {

            TabView {

                VStack {
                    NavigationLink(destination: Text("without tab")){
                      Text("aha")
                    }
                        .tabItem {
                            Text("b")
                    }
                }.tag(0)
                Text("Second View")
                    .tabItem {
                        GeometryReader { geometry in

                            Image(systemName: "2.circle")
                            //        Text("Second")
                            Text("\(geometry.size.height) - \(geometry.size.width)")

                        }
                }.tag(1)
            }
        }
    }//.isHidden(self.hideTabbar)
}

如果您使用的是导航控制器,则只需调用

self.parent?.navigationController?.pushViewController(yourViewController, animated: true)
导航到
ChildVC
此方法将不包括您的
TabBarView

创建CustumPresentViewController.swift-
谢谢你的回答。我确实使用标准的IOS环境。正如在我的代码中看到的,我有
TabBarView
,它调用
ExploreView
和其他视图。但是,当我点击
ExploreView
(文件
ExploreView
中的导航链接)的子视图时,
ExploreView
会自动更改为导航链接指向的
子视图,而不会隐藏底部的
选项卡栏。。谢谢您的回答!但我到底应该叫它什么呢?为了澄清我的问题:正如在我的代码中看到的,我有一个TabBarView,它调用ExploreView和其他视图。但当我点击ExploreView的子视图(ExploreView文件内部的NavigationLink)时,ExploreView会将自身更改为NavigationLink指向的子视图,而不会隐藏底部的选项卡栏..当按下下一个ViewController时,例如,当您点击ExploreView的子视图时,如果您有多个父导航控制器,则相应地在navigationController之前添加
.Parent?
。如果没有帮助,请告诉我。如果要在选项卡栏上显示视图,应使用“self.viewController?.present(样式:。全屏)”来显示视图。@ChamanSharma感谢您的回答!我是Swift用户界面的新手,不清楚该将其称为何处?我没有viewController…谢谢你的帮助,它工作得很好!你真的知道如何像导航链接那样改变视图吗?因为现在它是自下而上呈现的。
    import UIKit
    import SwiftUI

    struct ViewControllerHolder {
         weak var value: UIViewController?
    }

    struct ViewControllerKey: EnvironmentKey {
    static var defaultValue: ViewControllerHolder { return 
        ViewControllerHolder(value: 
        UIApplication.shared.windows.first?.rootViewController ) }
    }

    extension EnvironmentValues {
        var viewController: ViewControllerHolder {
            get { return self[ViewControllerKey.self] }
            set { self[ViewControllerKey.self] = newValue }
      }
    }

    extension UIViewController {
         func present<Content: View>(style: UIModalPresentationStyle = 
         .automatic, @ViewBuilder builder: () -> Content) {
             // Must instantiate HostingController with some sort of view...
             let toPresent = UIHostingController(rootView: 
              AnyView(EmptyView()))
             toPresent.modalPresentationStyle = style
             // ... but then we can reset rootView to include the environment
             toPresent.rootView = AnyView(
             builder()
            .environment(\.viewController, ViewControllerHolder(value: 
             toPresent))
    )
    self.present(toPresent, animated: true, completion: nil)
    }
}
@Environment(\.viewController) private var viewControllerHolder:  
ViewControllerHolder

private var viewController: UIViewController? {
    self.viewControllerHolder.value
}

var body: some View {
    NavigationView {
        ZStack {
            Text("Navigate")
        }.onTapGesture {
             self.viewController?.present(style: .fullScreen) {
                                    EditUserView()
             }
        }
    }
}