本文介绍了SwiftUI 在子视图中隐藏 TabBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 SwiftUI,但 TabBar 有一些问题.我想隐藏特定子视图上的 TabBar.

I am working with SwiftUI, and I have some issues with the TabBar.I want to hide the TabBar on a specific subview.

尝试过

UITabBar.appearance().isHidden = true

它仅适用于 TabView 中的直接视图.但是当我把它放在子视图中时它不起作用.

It only works on the direct views in the TabView. But when I place it in a subview it doesn't work.

有没有人解决这个问题?

Have anyone a solution for this?

谢谢.

推荐答案

iOS 14

安装 Introspect SwiftPM:https://github.com/siteline/SwiftUI-Introspect

struct SomeView: View{

    @State var uiTabarController: UITabBarController?

    var body: some View {
        List {
            -your code here-
        }

        .navigationBarTitle("Title", displayMode: .inline)
        .introspectTabBarController { (UITabBarController) in
            UITabBarController.tabBar.isHidden = true
            uiTabarController = UITabBarController
        }.onDisappear{
            uiTabarController?.tabBar.isHidden = false
        }
    }
}

uiTabarController中的这段代码中,我们引用了UITabarController.当我们返回时,我们再次启用了 Tabar.所以,这就是为什么需要这样做.

In this code in uiTabarController, we are taking the reference of UITabarController. When we go back then we enabled the Tabar again. So, that's why this is needed.

这篇关于SwiftUI 在子视图中隐藏 TabBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 05:43