In UIKit
world we are so used to hide bottom bar (aka TabBar) when we push to a new view controller. It’s pretty simple:
// DestinationViewController
func viewDidLoad() {
...
self.hidesBottomBarWhenPushed = true
}
And in SwiftUI
world, we need to make a little change:
DestinationScreen()
.toolbar(.hidden, for: .tabBar)
Sometimes you may find it doesn’t work well, the bottom bar is gone when we pushed to DestinationViewController
, but when we pop back, the bottom bar never shows up. In this case, we need to double check this point:
NavigationStack {
NavigationLink {
NewView()
.toolbar(.hidden, for: .tabBar)
} label: {
Image(systemName: "archivebox")
}
}
Always use NavigationStack
instead of legacy NavigationView
, and the problem is gone.