Reputation: 7855
My app has a custom navigation bar that is 59 (virtual) pixels tall, as opposed to the 44 pixels of the standard Apple UINavigationController UINavigationBar. I'm applying the styling to the bar with the following call during app startup:
UIImage *navBarImage = [UIImage imageNamed:@"navigation-bar.png"];
[[UINavigationBar appearance] setBackgroundImage:navBarImage
forBarMetrics:UIBarMetricsDefault];
The problem this leads to is that it's basically an image slapped on top of the screen at the origin of the standard navigation bar. The underlying navigation bar has no idea that its size has changed. This makes the content views (the view pushed onto the navigation stack) show up 15 pixels under the custom bar.
I couldn't find a way of changing the size and position of the UINavigationController's navigation view.
What is the most elegant way of accounting for this customization? The following (not elegant) works, BUT because the operations are applied after the view has been rendered, the shift in position and resizing is very visible to the user and looks quite amateurish:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
CGRect frame = self.view.frame;
self.view.frame = CGRectMake(frame.origin.x, frame.origin.y + 15, frame.size.width, frame.size.height - 15);
}
All of the controllers pushed onto the navigation stack are in a subclass of UIViewController that implements the method above.
Thanks a bunch!
Upvotes: 3
Views: 9814
Reputation: 690
I know this is old, but since you never got an answer, I thought I might post how I solved this issue.
I posted a similar question but had another problem in addition to yours. I was pointed to a question on how to set the height of a UINavigationBar, and the top answer worked perfectly for me. The user suggests creating a custom UINavigationBar category and overriding the -sizeThatFits method. It solves the problem of your app not recognizing the increased height of the UINavigationBar and also an additional problem of views in the UINavigationBar not being clickable below the default 44px bottom line.
Upvotes: 5