SwiftUI Hide TabView bar inside NavigationLink views
If we talk about standard TabView, the possible workaround solution can be based on TabBarAccessor
from my answer on Programmatically detect Tab Bar or TabView height in SwiftUI
Here is a required modification in tab item holding NavigationView
. Tested with Xcode 11.4 / iOS 13.4
struct FirstTabView: View {
@State private var tabBar: UITabBar! = nil
var body: some View {
NavigationView {
NavigationLink(destination:
FirstChildView()
.onAppear { self.tabBar.isHidden = true } // !!
.onDisappear { self.tabBar.isHidden = false } // !!
) {
Text("Go to...")
}
.navigationBarTitle("FirstTitle", displayMode: .inline)
}
.background(TabBarAccessor { tabbar in // << here !!
self.tabBar = tabbar
})
}
}
Note: or course if FirstTabView
should be reusable and can be instantiated standalone, then tabBar
property inside should be made optional and handle ansbsent tabBar explicitly.
Hiding tab bar on a specific page in SwiftUI
I updated my solution with TabView for your situation. The same idea: you're using ZStack
and @State var selection
. And the idea is to use .opacity
of TabView
and YourCameraView
(which is just Image(systemName: "plus.circle")
in my example):
struct TabViewModel: View {
@State var selection: Int = 0
var body: some View {
ZStack {
GeometryReader { geometry in
TabView(selection: self.$selection) {
Text("list")
.tabItem {
Image(systemName: "list.bullet.below.rectangle")
}.tag(0)
Text("plus")
.tabItem {
Image(systemName: "camera")
}.tag(1)
Text("more categories!")
.tabItem {
Image(systemName: "square.grid.2x2")
}.tag(2)
}
.opacity(self.selection == 1 ? 0.01 : 1)
Image(systemName: "plus.circle")
.resizable()
.frame(width: 60, height: 60)
.shadow(color: .gray, radius: 2, x: 0, y: 5)
.offset(x: geometry.size.width / 2 - 30, y: geometry.size.height - 80)
.onTapGesture {
self.selection = 0
}
.opacity(self.selection == 1 ? 1 : 0)
}
}
}
}
when you tap on camera tabItem TabView
becomes invisible
hide TabView after clicking on a NavigationLink in SwiftUI
There is no way to do that currently. For example, NavigationView
responds to the .navigationBarHidden(_:)
method on its descendants, but there is not an equivalent for TabView
.
If this is something you'd like to see, let Apple know.
How do I hide navigation bar in the tab bar's specific view in SwiftUI?
If you want to hide the navigation bar in a TabbedView
, you have to set .navigationBarHidden(true)
on the views nested inside TabbedView
. This isn't enough, however. For whatever reason, SwiftUI requires that you first set the navigation bar title before you can hide the navigation bar.
NavigationView {
TabbedView{
Rectangle()
.foregroundColor(.green)
.tag(0)
.tabItem{
Text("Page1")
}
.navigationBarTitle("")
.navigationBarHidden(true)
List(0...2) { i in
NavigationLink(destination: Text("\(i)")) {
Text("\(i)")
}
}
.tag(1)
.tabItem {
Text("Page2")
}
.navigationBarTitle("")
.navigationBarHidden(true)
}
}
Related Topics
Swift: How to Delete Part of Audio
Beginner Swift Sprite Kit - Node Collision Detection Help (Skphysicscontact)
Swift Http Request Use Urlsession
Compare Textfield.Text to Firebase String Swift
Default Argument Not Permitted in a Tuple Type When Defining Function Type
Swift 2 Array of Tuples Not Working as in Swift 1
Storing/Passing Function Types from Swift Protocols
Ambiguous Use of Subscript (Swift 3)
What Is the Way to Save Fonts and Sizes in Firebase for Textview Swift
Expandable Sections Uitableview Indexpath Swift
How to Create an Array of Functions
Make Int Round Off to Nearest Value
Change Uibarbuttonitem from Uisearchbar
Diagnosing Exc_Bad_Instruction in Swift Standard Library
How to Use Combine to Track Uitextfield Changes in a Uiviewrepresentable Class