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
viewDidLoadthe 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, 320×480 for an iPhone app).The view then autoresizes to take into account the navigation bar. So when you check the frame size in
viewWillAppearit 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.