如何在项目范围内显示选项卡栏控制器的底部选项卡?

How to display bottom tab of tab bar controller project wide?

class func tabBarController () -> UINavigationController{
    
    let tabBarController = UITabBarController()
    
    let homeVC = UIStoryboard(name: "Home", bundle: nil).instantiateViewController(withIdentifier: "HomeVC")
    
    let wishlistVC = UIStoryboard(name: "Wishlist", bundle: nil).instantiateViewController(withIdentifier: "WishlistVC")
    
    homeVC.tabBarItem = UITabBarItem(title: "Home", image: UIImage(named: "home"), selectedImage: UIImage(named: "home"))
    
    wishlistVC.tabBarItem = UITabBarItem(title: "Wishlist", image: UIImage(named: "wishlist"), selectedImage: UIImage(named: "wishlist"))
    
    tabBarController.tabBar.tintColor = .black
    tabBarController.tabBar.isTranslucent = false
    tabBarController.tabBar.barTintColor = UIColor.white
    tabBarController.tabBar.layer.shadowOffset = CGSize(width: 0, height: 0.3)
    tabBarController.tabBar.layer.shadowRadius = 4.0
    tabBarController.tabBar.layer.shadowColor = UIColor.gray.cgColor
    tabBarController.tabBar.layer.shadowOpacity = 0.2
    tabBarController.tabBar.clipsToBounds = false
    tabBarController.tabBar.backgroundImage = UIImage()
    tabBarController.tabBar.shadowImage = UIImage()
    tabBarController.hidesBottomBarWhenPushed = true

    let tabBarViewController = [homeVC, wishlistVC]
    
    let navigationController = UINavigationController.init(rootViewController: tabBarController)
    navigationController.navigationBar.isTranslucent = true
    navigationController.navigationBar.shadowImage = UIImage()
    navigationController.navigationBar.topItem?.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: self, action: nil)
    navigationController.navigationBar.tintColor = UIColor.darkGray
    navigationController.view.backgroundColor = UIColor(named: "background_color")
    navigationController.navigationBar.barTintColor = .white
    let attributes = [NSAttributedString.Key.font: UIFont(name: "Roboto-Medium", size: 18)!]
    navigationController.navigationBar.titleTextAttributes = attributes
    
    return navigationController
}

这是我实现标签栏控制器的编程方式。

当按下另一个视图控制器时,我希望底部选项卡也显示在其他屏幕上。

** 请任何人帮助我 ** 提前致谢

您需要像这样构建视图层次结构

- tabBarController
     - navigation 1
        - vc 1
     - navigation 2
        - vc 2

这背后的想法是,当您将 tabController 包装在导航中并推送 vc 时,它会占据整个屏幕,而当您将 vc 推送到特定选项卡内的导航时它保留下面的选项卡,因为导航在选项卡内

let navi1 = UINavigationController(rootViewController: homeVC)
// configure  navi1
.....
.....
let navi2 = UINavigationController(rootViewController: wishlistVC)
// configure  navi2
.....
.....
tabBarController.viewControllers = [navi1,navi2]