Domness
Domness

Reputation: 7605

Hide Navigation Bar on rotation

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?

Upvotes: 6

Views: 7296

Answers (3)

adam
adam

Reputation: 22587

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

Upvotes: 9

Alfons
Alfons

Reputation: 1845

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.

Upvotes: -2

August
August

Reputation: 12187

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

Upvotes: 8

Related Questions