0

我有一个带有自定义 TabBar 和覆盖的 TabView:https ://jboullianne.medium.com/custom-tabbar-e8f2ea89d2fc

我能够使用 Introspect 在子视图中隐藏 TabBar:https ://github.com/siteline/SwiftUI-Introspect

但我也想隐藏子视图中的覆盖以完全隐藏 TabBar。

我该如何隐藏它?

我的测试代码试图隐藏 TabBar(工作,请参阅 TestTabBarPage3)和覆盖(如何???):

测试标签栏

struct TestTabBar: View {
    var body: some View {
        TabView {
            TestTabBarPage1()
                .tabItem {
                    Image(systemName: "envelope")
                    Text("TestTabBarPage1")
                }
            
            TestTabBarPage2()
                .tabItem {
                    Image(systemName: "star")
                    Text("TestTabBarPage2")
                }
            
        }
        .overlay(
            Color(#colorLiteral(red: 0.259467423, green: 0.5342320204, blue: 0.7349982858, alpha: 1))
                .frame(height: 50)
                .offset(y: 40)
        )
    }
}

TestTabBarPage1

struct TestTabBarPage1: View {
    var body: some View {
        Text("TestTabBarPage1")
            .navigationBarTitle(Text("TestTabBarPage2"), displayMode:.inline)
    }
}

TestTabBarPage2

struct TestTabBarPage2: View {
    var body: some View {
        NavigationView {
            NavigationLink(destination: TestTabBarPage3()) {
                Text("TestTabBarPage3")
            }
            .navigationBarTitle(Text("TestTabBarPage2"), displayMode:.inline)
        }
    }
}

TestTabBarPage3

struct TestTabBarPage3: View {
    @State var uiTabarController: UITabBarController?
    
    var body: some View {
        Text("Hello, World!")
            .navigationBarTitle(Text("TestTabBarPage3"), displayMode:.inline)
            .introspectTabBarController { (UITabBarController) in
                UITabBarController.tabBar.isHidden = true
                uiTabarController = UITabBarController
            }.onDisappear{
                uiTabarController?.tabBar.isHidden = false
            }
    }
}
4

0 回答 0