导航控制器栏无故较低。

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

Navigation controller bar is low for no reason

问题

我创建了一个Tab Bar控制器,其中包含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()

请注意,上述代码中的注释已经被翻译成中文。

英文:

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-2.html
匿名

发表评论

匿名网友

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

确定