How do I hide navigation bar in the tab bar's specific view in SwiftUI?

前端 未结 1 872
清歌不尽
清歌不尽 2021-01-19 07:03

XCode11 beta3, MacOS Catalina 10.15 Beta(19A501i)

I want to hide tabBar when push~ Any command will very helpful, Thanks~

Click me to show gif image :

相关标签:
1条回答
  • 2021-01-19 07:18

    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)
        }
    }
    
    0 讨论(0)
提交回复
热议问题