TabBarViewController的导航栏涵盖了导航控制器中的导航栏

时间:2018-12-08 09:09:10

标签: ios swift swift4

我正在尝试使用UITabBarController中的选项卡栏,同时使用Navigation Controller中的导航栏。如果将导航控制器的根控制器设置为“标签栏视图”控制器,则会得到图像2。如果将根控制器设置为主视图控制器(即“标签栏”项0),则会得到图片1。

IMG:
所需的导航栏

IMG:
所需的标签栏

我不使用情节提要,现在我的层次结构如下:

NavigationController->UITabBarController->ViewControllers

AppDelegate.swift:

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.

    window = UIWindow(frame: UIScreen.main.bounds)
    window?.makeKeyAndVisible()
    window?.rootViewController = UINavigationController(rootViewController: TabViewController())

    return true
}

1 个答案:

答案 0 :(得分:0)

之所以发生这种情况,是因为如果您有多个navigationController或NavigationBar,则默认情况下,初始导航栏将覆盖下一个NavigationBar。您可以通过将初始navigationController的导航栏设置为隐藏

来获得所需的结果
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

 window = UIWindow(frame: UIScreen.main.bounds)
 window?.makeKeyAndVisible()
 let navigation =  UINavigationController(rootViewController: TabViewController()) 
 navigation.setNavigationBarHidden(true, animated: false)
 window?.rootViewController = navigation
 return true 
}