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
2009-01-12 19:10:42
A:
Cheers, thanks a lot. Seems to have done the trick. Just need to get it shown again when put back to portrait :)
Domness
2009-01-12 19:15:02
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
2009-01-13 21:17:23
A:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[[self navigationController] setNavigationBarHidden:UIInterfaceOrientationIsLandscape(toInterfaceOrientation) animated:YES];
[[UIApplication sharedApplication] setStatusBarHidden:UIInterfaceOrientationIsLandscape(toInterfaceOrientation) animated:YES];
}
adam
2010-02-27 13:15:08