Swift - 展开TabBar后面的ViewController

时间:2018-04-18 15:27:07

标签: swift

我在tabItems中创建了三个UITabBarViewController,它被推送到另一个UINavigationController。三个tabItem中的一个是UINavigationController,另外两个是UIViewController。为了确保在作为UINavigationController的tabItem的非root viewController中只显示一个导航栏,将隐藏父UINavigationBar。

override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        if let navigationC = self.navigationController, navigationC.viewControllers.count == 1 {
            self.navigationController?.setNavigationBarHidden(true, animated: false)
            self.parent?.navigationController?.setNavigationBarHidden(false, animated: false)
        } else {
            self.navigationController?.setNavigationBarHidden(false, animated: false)
            self.parent?.navigationController?.setNavigationBarHidden(true, animated: false)
        }
        self.setupViewConstraints()
    }

此问题是,如果我导航到UIViewController的第二个UINavigationController,请从UINavigationController切换到UIViewController并返回UINavigationControllerUINavigationController的底部向上移动,应该等于UIScreen的底部。如果我导航回UINavigationController的根视图,则UINavigationcontroller的底部等于正确的UIScreen

如何确保navigationController中的所有UIViewControllers'底部都等于UIScreen?它可能是由于UINavigationController tabItem的非根视图控制器中有两个navigationBar。

以下是我用来创建UITabBarViewController的代码:

override func viewDidLoad() {
    super.viewDidLoad()
    tabBar.tintColor = UIColor.fromHexString("0078d7")
    tabBar.barTintColor = UIColor.white

    let firstViewController = FirstViewController()
    firstViewController.delegate = self
    firstViewController.tabBarItem = UITabBarItem.init(title: "first", image: , tag: 0)


    let secondViewController = SecondViewController()
    secondViewController.delegate = self
    secondViewController.tabBarItem = UITabBarItem.init(title: "second", image: , tag: 1)

    let thirdViewController = ThirdViewController()
    thirdViewController.delegate = self
    thirdViewController.tabBarItem = UITabBarItem.init(title: "third", image: , tag: 3)

    let initialNavigationController = UINavigationController(rootViewController: firstViewController)
    initialNavigationController.navigationItem.title =  ""
    self.addChildViewController(initialNavigationController)
    self.addChildViewController(secondViewController)
    self.addChildViewController(thirdViewController)

    self.navigateToLastVisitedViewController(navigationController: initialNavigationController)
}

1 个答案:

答案 0 :(得分:0)

在上述viewDidLoad UITabBarViewController tabBar方法中,只需制作translucent viewController。这样您就可以将内容UITabBar放在self.tabBar.isTranslucent = true 对象下面。

夫特

[self.tabBar setTranslucent:YES];

的Objective-C

UINavigationBar
  

在{{1}}案例中将使用相同的逻辑。