Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone navigation bar height remains short in portrait orientation

My app's root view controller supports any orientation but user can navigate to another view controller that supports only landscape orientation.

The basic problem is that regardless of the device's actual physical orientation, when the user pops back to root view controller, the navigation bar has a height that would be appropriate for landscape mode. I would like to figure out how to get navigation bar to appear with height of 44 (portrait height) instead of 32 (landscape height).

Although the navigation bar is not set to proper height, the root view controller's UITableView is offset correctly (44 pixels from top of screen).

Inside the second view controller's -viewWillAppear: I perform the standard rotational transform:

if (deviceOrientation == UIDeviceOrientationPortrait)
   {
   UIScreen *screen = [UIScreen mainScreen];
   CGFloat screenWidth = screen.bounds.size.width;
   CGFloat screenHeight = screen.bounds.size.height;
   UIView *navView = [[self navigationController] view];
   navView.bounds = CGRectMake(0, 0, screenHeight, screenWidth);
   navView.transform = CGAffineTransformIdentity;
   navView.transform = CGAffineTransformMakeRotation(degreesToRadians(90));
   navView.center = CGPointMake(screenWidth/2.0, screenHeight/2.0);
   [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
   }

Because this secondary view controller allows navigation to subordinate view controllers (as well as popping back up to root view controller), I have added the following to -viewWillDisappear:

if (deviceOrientation == UIDeviceOrientationPortrait)
   {
   UIScreen *screen = [UIScreen mainScreen];
   CGFloat screenWidth = screen.bounds.size.width;
   CGFloat screenHeight = screen.bounds.size.height;
   UIView *navView = [[self navigationController] view];
   navView.bounds = CGRectMake(0, 0, screenWidth, screenHeight);
   navView.transform = CGAffineTransformIdentity;
   navView.center = CGPointMake(screenWidth/2.0, screenHeight/2.0);
   [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
   }

Thanks for any advice on how to force recalculation of navigation bar height.

like image 471
westsider Avatar asked Jul 27 '10 00:07

westsider


People also ask

What is the height of navigation bar iPhone?

On iPhone tab bars remain 49 points tall in portrait and 32 points tall in landscape.

What is the ios navigation bar?

A navigation bar appears at the top of an app screen, below the status bar, and enables navigation through a series of hierarchical app screens. When a new screen is displayed, a back button, often labeled with the title of the previous screen, appears on the left side of the bar.


1 Answers

Not sure if there's a better way, but this worked:

[[self navigationController] setNavigationBarHidden:YES animated:NO];
[[self navigationController] popViewControllerAnimated:YES];
[[self navigationController] setNavigationBarHidden:NO animated:NO];

Basically, hide the nav bar, pop the view controller and the show the nav bar. Some code somewhere adjusts the nav bar height and everything's fine.

like image 83
westsider Avatar answered Nov 12 '22 17:11

westsider