为什么我的根视图的高度不考虑其导航栏? [英] Why doesn't my root view's height take account of its navigation bar?

查看:122
本文介绍了为什么我的根视图的高度不考虑其导航栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的印象是,UINavigationController的导航栏将总是压下子视图的高度,这样子视图的原点在标题栏的底部。



但是当我提出一个视图控制器这样...

  MyViewController * viewController = [[MyViewController alloc] init]; 
UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
viewController.title = @我的视图控制器;
viewController.navigationItem.prompt = @我的提示;
viewController.delegate = self;

[self presentModalViewController:navigationController animated:YES];
[navigationController release]; [viewController release];

...然后检查 self.view.frame.size.height 使用 viewDidLoad 中的NSLog,它报告我的视图高460px。不应该减去我的头衔和身高的高度。提示?

解决方案

因此,根据要求:



c $ c> viewDidLoad 视图控制器尚未推送到屏幕上。因此,当您从该方法中获取帧大小时,它会报告其默认值(通常为iPhone应用程序的320x480)。



视图随后会自动调整大小导航栏。因此,当您在 viewWillAppear 中检查框架大小时,它现在是正确的。通常这不是iPhone应用程序的问题。对于iPad应用程序,您有多个方向,它可能有点痛苦!



这有一些例外 - 例如,当使用NIBs。 / p>

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];

... 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?

解决方案

So, as requested:

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).

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!

There are a few exceptions to this - for example, when using NIBs.

这篇关于为什么我的根视图的高度不考虑其导航栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆