我创建了一个选项卡栏控制器,其中有 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”标识符的视图控制器实际上是故事板顶部的选项卡栏,所以也许我的场景委托有问题,但我不知道为什么这会对导航栏的位置产生影响.
检查您是否已选择“偏好大标题”(如果则取消选中)。
您问题中的代码:
// 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()
也就是说......你为什么不直接在项目设置中设置它?为什么要从代码加载?