gpt4 book ai didi

ios - TabBarViewController 的导航栏覆盖了导航 Controller 中的导航栏

转载 作者:行者123 更新时间:2023-11-30 10:58:25 24 4
gpt4 key购买 nike

我正在尝试使用导航 Controller 中的导航栏,同时使用 UITabBarController 中的选项卡栏。如果我将导航 Controller 的根 Controller 设置为我的选项卡栏 View Controller ,我会得到图像 2。如果我将根 Controller 设置为我的主视图 Controller (即选项卡栏项目 0),我会得到图像 1。

IMG:
所需的导航栏

IMG:
所需的标签栏

我没有使用 Storyboard,现在我的层次结构如下:

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
}

最佳答案

发生这种情况是因为如果您有多个导航 Controller 或导航栏,则默认情况下初始导航栏将覆盖下一个导航栏。您可以通过将初始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
}

关于ios - TabBarViewController 的导航栏覆盖了导航 Controller 中的导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53681082/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com