【问题标题】:Hide Navigation bar for `TabView` not working隐藏“TabView”的导航栏不起作用
【发布时间】:2021-01-06 08:56:30
【问题描述】:

在 swiftUI 中,iOS14。我无法隐藏TabView 的导航栏。这是我的代码:

struct ContentView: View {
    var body: some View {
        NavigationView {
            TabView() {
                List {
                    Text("Hi!")
                    Text("How are you?")
                }
            }
            .navigationTitle("")
            .navigationBarHidden(true) // not working!!
        }
    }
}

这是一个错误吗?如何解决这个问题?

【问题讨论】:

    标签: swiftui navigationbar ios14 tabview


    【解决方案1】:

    您需要将.navigationBarHidden(true) 移到 TabView 内部

    
      struct ContentView: View {
            var body: some View {
                NavigationView {
                    TabView() {
                        List {
                            Text("Hi!")
                            Text("How are you?")
                        }
                        .navigationBarHidden(true) //<= here
                    }
                }
            }
        }
    
    

    【讨论】:

    • 这隐藏了导航栏,检查我已将 .navigationBarHidden(true) 添加到列表中
    • 哦!需要在TabView里面添加代码。魔法!
    猜你喜欢
    • 1970-01-01
    • 2020-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多