导航控制器栏无故变低

huangapple go评论124阅读模式
英文:

Navigation controller bar is low for no reason

问题

我创建了一个 Tab Bar Controller,其中包含 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" 的视图控制器实际上是位于故事板顶部的选项卡栏,所以也许我的场景代理存在问题,但我不知道为什么这会影响导航栏的位置。

英文:

I created a Tab Bar Controller, with 4 navigation controllers each containing one view controller, but on these view controllers, the bar titles are super low. It doesn't matter if I choose large title or not, the issue is the same with regular titles.
Is it because of the tab bar?

导航控制器栏无故变低

导航控制器栏无故变低

导航控制器栏无故变低

Does someone knows how to fix it? When I set a custom frame for the navigation bar it doesn't have any influence.
And when I push a new view controller, we can't interact with anything that's in the first 25% of the screen (probably because it's behind the navigation bar title, even when i set it to none). That's really weird, how do I set the titles higher or just disable them?

This is also what's in my scene delegate :

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

The view controller with Identifier 'Main' is actually to tab bar at the top of the storyboard, so maybe there's an issue with my scene delegate, but I don't know why this could have an influence on the position of the navigation bar.

答案1

得分: 1

你的问题中的代码如下:

// 从名为“TabBar”的Storyboard中实例化具有标识符“Main”的UITabBarController
let storyboard = UIStoryboard(name: "TabBar", bundle: nil).instantiateViewController(withIdentifier: "Main") as! UIViewController

// 创建一个新的UINavigationController,将实例化的UITabBarController作为其根视图控制器
let navigation = UINavigationController(rootViewController: storyboard)

// 显示导航控制器
window?.rootViewController = navigation
window?.makeKeyAndVisible()

所以,你有:

  • 一个导航控制器(带有自己的导航栏)
  • 包含一个标签栏控制器
  • 每个标签都有自己的导航控制器和导航栏

将你的代码更改为以下内容(尽管对象命名非常混乱):

// 从名为“TabBar”的Storyboard中实例化具有标识符“Main”的UITabBarController
let storyboard = UIStoryboard(name: "TabBar", bundle: nil).instantiateViewController(withIdentifier: "Main") as! UIViewController

// 显示标签栏控制器
window?.rootViewController = storyboard
window?.makeKeyAndVisible()

话虽如此...为什么你不直接在项目设置中设置呢?为什么要通过代码加载呢?

英文:

This code from your question:

// 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()

So, you have:

  • a Navigation Controller (with its own navigation bar)
  • holding a Tab Bar Controller
  • each tab has its own navigation controller and navigation bar

Change your code to this (although it is very confusing object naming):

// 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()

That said... why are you not setting that directly in your project setup? Why do this loading from code?

答案2

得分: 0

请检查是否选择了“偏好大标题”(如果选择了,请取消选择)。

英文:

导航控制器栏无故变低

Check if you have selected Prefers Large Titles (If then uncheck it).

huangapple
  • 本文由 发表于 2023年8月9日 15:38:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76865572.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定