ios - 在 loadView 期间或之前获取 UINavigationController 的内部 contentView 的 CGRect 框架

标签 ios uinavigationcontroller

Apple 的文档说:

Note: Because the amount of space available for the custom view can vary
(depending on the size of the other navigation views), your custom view’s
autoresizingMask property should be set to have a flexible width and height.
Before displaying your view, the navigation controller automatically
positions and sizes it to fit the available space.

这很好,除了......我需要知道 UINavController 将使用的大小 BEFORE 将 View 添加到框架,因为我将显示的内容因大小而异。

这是在添加到 UINavigationController 的 UIViewController 的“loadView”方法中。

最佳答案

好吧,从技术上讲,您不应该在 loadView 方法中调整 subview 的大小。我不使用 nib,并且在我几乎所有的 View Controller 中,loadView 都非常小:self.view = [[UIView alloc] init];。然后,在 viewDidLoad 中,我将所有 subview 添加到 self.view。最后,我在 viewWillAppear 中调整了所有大小,因为此时 self.view 将是合适的大小。

如果您必须在 loadView 方法中调整 View 大小,则必须手动计算尺寸...即:找出设备的方向(self.interfaceOrientation) 确定屏幕大小,减去您认为屏幕上的任何其他元素(如导航栏等)。但是不推荐这种方法。

关于ios - 在 loadView 期间或之前获取 UINavigationController 的内部 contentView 的 CGRect 框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9605824/

相关文章:

php - 阿拉莫菲尔!在分段文件上传中,progress.isPausable返回false,并且progress.pause()不起作用

ios - coreData 中的关系如何运作

ios - UINavigationBar 在推送时更改颜色

iphone - 弹出一个基本 View 。它会弹出所有 subview 吗?

ios - UINavigationController - 检测何时导航回 Root View Controller

ios - 团队未在 iTunes Connect 上显示

ios - 使用 Fabric SDK iOS 访问 Twitter 用户时间线

python - Appium中如何获取iOS设备显示的最大宽高坐标?

ios - swift | UIButton 导致点击时崩溃

iphone - self.tabBarItem.title 不起作用?