tags:

views:

1873

answers:

5

I have a UIView with a navigation bar. How can I hide the navigation bar when the user puts the iPhone in landscape orientation, and have it show again on portrait view?

+4  A: 

This is very easy to find in the documentation. In the UINavigationController docs, to hide the nav bar, you use:

- (void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated

If you want to do this when the device rotates, you'll want to do this in your the view controller method (mentioned in the UIViewController docs):

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
August
A: 

Cheers, thanks a lot. Seems to have done the trick. Just need to get it shown again when put back to portrait :)

Domness
A: 

A better way IMHO is to use a CGAffineTransform, and leave the nav bar where it is - like the photo gallery view of the iPhone. See Jeff Lamarche's excellent introduction Demystifying CGAffineTransform. Helped me quite a bit.

Alfons
A: 

I have some problems on rotating back to Portrait mode... What exactly should I do on didRotate ?

A: 
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    [[self navigationController] setNavigationBarHidden:UIInterfaceOrientationIsLandscape(toInterfaceOrientation) animated:YES];
    [[UIApplication sharedApplication] setStatusBarHidden:UIInterfaceOrientationIsLandscape(toInterfaceOrientation) animated:YES];
}
adam