Reputation: 7605
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
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
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
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