[英]How to hide the TabBar when navigate with NavigationLink in SwiftUI?
I have a TabView with 2 tabs in it, each tab containing a NavigationView.我有一个带有 2 个选项卡的 TabView,每个选项卡都包含一个 NavigationView。 I need to hide the TabBar
when navigating to another view.导航到另一个视图时,我需要隐藏TabBar
。 One solution would be to place the TabView
inside of one NavigationView, but I have to set different properties for each NavigationView.一种解决方案是将TabView
放在一个 NavigationView 中,但我必须为每个 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)
})
PS I am using Xcode 11 Beta 5 PS 我正在使用 Xcode 11 Beta 5
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 之前,当您在选项卡式视图中使用导航链接时,选项卡按钮将被隐藏。
NavigationView{
TabView{
...
}
}
I have a TabView with 2 tabs in it, each tab containing a NavigationView.我有一个带有2个标签的TabView,每个标签都包含一个NavigationView。 I need to hide the TabBar
when navigating to another view.导航到另一个视图时,我需要隐藏TabBar
。 One solution would be to place the TabView
inside of one NavigationView, but I have to set different properties for each NavigationView.一种解决方案是将TabView
放在一个NavigationView内,但是我必须为每个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)
})
PS I am using Xcode 11 Beta 5 PS我正在使用Xcode 11 Beta 5
I have same problem for this;我对此有同样的问题; And I did the following actions to solve this problem:我做了以下操作来解决这个问题:
NavigationView Contain a TabView
And Hidden the NavigationBar
使用NavigationView Contain a TabView
并Hidden the NavigationBar
// root tab
NavigationView {
TabView {
// some
}
.navigationBarTitle(xxx, displayMode: .inline)
.navigationBarHidden(true)
}
// custom navigation view
@available(iOS 13.0.0, *)
struct MyNavigationView: View {
var body: some View {
HStack {
Spacer()
Text(some)
Spacer()
}
.frame(height: 44)
}
}
// this view
VStack {
MyNavigationView()
Image(some)
.resizable()
.frame(width: 100, height: 100, alignment: .top)
.padding(.top, 30)
Spacer()
HStack {
ClockView()
Spacer()
NavigationLink(
destination: DynamicList(),
label: {
Image(some)
}).navigationBarHidden(true)
}
.padding(EdgeInsets(top: 0, leading: 15, bottom: 0, trailing: 15))
Spacer()
}
// next view
var body: some View {
VStack {
List {
MyNavigationView()
ForEach(date, id: \.self) { model in
Text(model)
}
}
.navigationBarHidden(true)
.navigationBarTitle(some, displayMode: .inline)
}
}
据我所知,如果您将导航视图列为子项,则您无法隐藏标签栏,您的标签栏包含您的导航视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.