【问题标题】:Differing bounds in UITabBarController, UINavigationController and child UIViewControllerUITabBarController、UINavigationController 和子 UIViewController 中的不同边界
【发布时间】:2012-10-01 04:54:03
【问题描述】:

我一直在查看一些关于边界与框架的帖子,但仍然有点困惑。

我有以下层次结构:UITabBarController > UINavigationController > UIViewController

当我尝试以下 NSLog 时

NSLog(@"%f %f %f",[[[self tabBarController] view] bounds].size.height, [[[self navigationController] view] bounds].size.height, [[self view] bounds].size.height);

我得到以下输出:

480.000000 431.000000 460.000000

我了解状态栏高度的 20 个差异说明,但我不明白为什么 UIViewController 的边界不包括状态栏高度,但 UINavigationController 和 UITabBarController 的边界包括...

完善我的问题

1) 为什么top tabBarController 的高度是480.0(为什么不排除状态栏高度20pt???)。好的,让我假设 height 将始终不排除状态栏高度并继续前进

2) UINavigationController 的高度为 431.0(好吧,合理的猜测是它是 480-49,其中 49 是标签栏的高度)。但是为什么它选择性地排除标签栏的高度而不是状态栏的高度??? Apple 的 View Programming Guide 似乎没有解释这一点……但让我们继续……

3) 为什么我的 UIViewController 的高度是 460?!

(3a) 为什么它不像UITabBarController和UINavigationController那样排除状态栏的20pt高度???

(3b) 更重要的是,为什么它不排除导航栏的高度(即为什么不应该是 431-44 = 387?!)

(3c) 为什么我的 UIViewController INSIDE 我的 UINavigationController 比 UINavigationController 有 LONGER 高度???

【问题讨论】:

  • 阅读有关 UIViewControllers 的 Apple 指南 - 它完全解释了这些视图如何组合在一起。
  • @DavidH - 抱歉无知。我查看了 Apple 关于 UIViewController 类和 View Controller Programming Guide for iOS 的文档,它几乎没有提到边界
  • 抱歉,这是“查看编程指南”。
  • @DavidH - 谢谢大卫,我通读了指南,但它没有回答我的问题(我之前犯了一个错误,请查看修复该问题的编辑,我已经扩展了我的问题,请让我知道导游在哪里回答了我的问题?)。

标签: iphone ios uiviewcontroller uinavigationcontroller uitabbarcontroller


【解决方案1】:

有点想通了...我将 NSLog 放在 viewDidLoad 中,如果我将它们移动到 viewDidAppear,UIViewController 的高度正如预期的那样是 367 (=480-20-44-49),它的原点是 (0 , 64), 占状态栏的20pt和导航栏的44pt

对于 UINavigationController,即使它的 origin.y 为 0 并且高度为 480.0,当我直接打印其导航栏的框架时,导航栏的 origin.y 为 20,所以基本上 UINavigationController 的框架是仍处于全屏状态,但顶部 20pt(状态栏所在的位置)为空

【讨论】:

  • 你说得对……我已经编辑过了。感谢您指出这一点!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多