问题描述
我有一个带有 2 个选项卡的 TabView,每个选项卡都包含一个 NavigationView.导航到另一个视图时,我需要隐藏 TabBar
.一种解决方案是将 TabView
放在一个 NavigationView 内,但我必须为每个 NavigationView 设置不同的属性.
I have a TabView with 2 tabs in it, each tab containing a NavigationView. I need to hide the TabBar
when navigating to another view. One solution would be to place the TabView
inside of one NavigationView, but I have to set different properties for each NavigationView.
TabView(selection: $selectedTab, content: {
NavigationView {
VStack {
NavigationLink(destination: Text("SecondView Tab1")) {
Text("Click")
}
}
}.tabItem {
Text("ONE")
}.tag(0)
NavigationView {
VStack {
NavigationLink(destination: Text("SecondView Tab2")) {
Text("Click")
}
}
}.tabItem {
Text("TWO")
}.tag(1)
})
附言我正在使用 Xcode 11 Beta 5
P.S. I am using Xcode 11 Beta 5
推荐答案
有点晚,但它会起作用,将您的 NavigationView 放在 TabView 之前,当您在选项卡式视图中使用导航链接时,选项卡按钮将被隐藏.
A little late but it will work, put your NavigationView before the TabView and the tab buttons are going to be hidden when you use a navigation link in your tabbed views.
NavigationView{
TabView{
...
}
}
这篇关于在 SwiftUI 中使用 NavigationLink 导航时如何隐藏 TabBar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!