导航控制器栏无缘无故变低

问题描述 投票:0回答:2

我创建了一个选项卡栏控制器,其中有 4 个导航控制器,每个控制器包含一个视图控制器,但在这些视图控制器上,栏标题非常低。无论我是否选择大标题,问题都与普通标题相同。 是因为标签栏的原因吗?

有人知道如何解决吗?当我为导航栏设置自定义框架时,它没有任何影响。 当我推送一个新的视图控制器时,我们无法与屏幕前 25% 的任何内容进行交互(可能是因为它位于导航栏标题后面,即使我将其设置为“无”)。这真的很奇怪,我该如何将标题设置得更高或只是禁用它们?

这也是我的场景委托中的内容:

let storyboard = UIStoryboard(name: "TabBar", bundle: nil).instantiateViewController(withIdentifier: "Main") as! UIViewController
let navigation = UINavigationController(rootViewController: storyboard)
window?.rootViewController = navigation
window?.makeKeyAndVisible()

带有“Main”标识符的视图控制器实际上是故事板顶部的选项卡栏,所以也许我的场景委托有问题,但我不知道为什么这会对导航栏的位置产生影响.

ios swift xcode uiviewcontroller uinavigationcontroller
2个回答
0
投票

enter image description here

检查您是否已选择“偏好大标题”(如果则取消选中)。


0
投票

您问题中的代码:

// instantiate the UITabBarController with identifier "Main"
//  from Storyboard named "TabBar"
let storyboard = UIStoryboard(name: "TabBar", bundle: nil).instantiateViewController(withIdentifier: "Main") as! UIViewController

// create a new UINavigationController, with the 
//  instantiated UITabBarController as its Root View Controller
let navigation = UINavigationController(rootViewController: storyboard)

// show the navigation controller
window?.rootViewController = navigation
window?.makeKeyAndVisible()

所以,你有:

  • 导航控制器(带有自己的导航栏)
  • 按住标签栏控制器
  • 每个选项卡都有 自己的导航控制器和导航栏

将代码更改为此(尽管对象命名非常混乱):

// instantiate the UITabBarController with identifier "Main"
//  from Storyboard named "TabBar"
let storyboard = UIStoryboard(name: "TabBar", bundle: nil).instantiateViewController(withIdentifier: "Main") as! UIViewController

// show the tab bar controller
window?.rootViewController = storyboard
window?.makeKeyAndVisible()

也就是说......你为什么不直接在项目设置中设置它?为什么要从代码加载?

© www.soinside.com 2019 - 2024. All rights reserved.