SwiftUI在子视图中隐藏TabBar [英] SwiftUI hide TabBar in subview
本文介绍了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
var body: some View {
List {
-your code here-
}
.navigationBarTitle("Title", displayMode: .inline)
.introspectTabBarController { (UITabBarController) in
UITabBarController.tabBar.isHidden = true
}
}
注意:您必须在父视图中重新启用它的TabBar,否则它仍将被隐藏.
NOTE: You have to re-enable the TabBar it in the parent view or it will still be hidden.
.introspectTabBarController { (UITabBarController) in
UITabBarController.tabBar.isHidden = false
}
这篇关于SwiftUI在子视图中隐藏TabBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文