我在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
并返回UINavigationController
,UINavigationController
的底部向上移动,应该等于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)
}
答案 0 :(得分:0)
在上述viewDidLoad
UITabBarViewController
tabBar
方法中,只需制作translucent
viewController
。这样您就可以将内容UITabBar
放在self.tabBar.isTranslucent = true
对象下面。
[self.tabBar setTranslucent:YES];
UINavigationBar
在{{1}}案例中将使用相同的逻辑。