问题描述
我的印象是 UINavigationController 的导航栏总是会向下推子视图的高度,这样子视图的原点就在标题栏的底部.
I was under the impression that a UINavigationController's navigation bar would always push down the child view's height, such that the child view's origin was at the bottom of the title bar.
但是当我呈现这样的视图控制器时......
But when I present a view controller like this ...
MyViewController *viewController = [[MyViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
viewController.title = @"My View Controller";
viewController.navigationItem.prompt = @"My Prompt";
viewController.delegate = self;
[self presentModalViewController:navigationController animated:YES];
[navigationController release]; [viewController release];
... 然后用 viewDidLoad 中的 NSLog 检查 self.view.frame.size.height,它报告我的视图是 460px 高.它不应该减去我标题的高度吗?迅速的?
... and then check self.view.frame.size.height with an NSLog in viewDidLoad, it reports that my view is 460px high. Shouldn't it subtracting the height of my title & prompt?
推荐答案
所以,按照要求:
当您调用 viewDidLoad 时,视图控制器还没有被推送到屏幕上.因此,当您从该方法中获取帧大小时,它将报告其默认值(对于 iPhone 应用,通常为 320x480).
When you call viewDidLoad the view controller hasn't been pushed onto the screen yet. So when you get the frame size from within that method it will report its' default (typically, 320x480 for an iPhone app).
然后视图会自动调整大小以考虑导航栏.因此,当您在 viewWillAppear 中检查帧大小时,它现在是正确的.通常这对 iPhone 应用程序来说不是问题.对于 iPad 应用程序,您有多个方向,这可能会有点痛苦!
The view then autoresizes to take into account the navigation bar. So when you check the frame size in viewWillAppear it will now be correct. Typically this isn't a problem for iPhone apps. For iPad apps, where you have multiple orientations, it can be a bit of a pain!
这有一些例外 - 例如,使用 NIB 时.
There are a few exceptions to this - for example, when using NIBs.
这篇关于为什么我的根视图的高度不考虑它的导航栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)