我有一个带导航栏的UIView.当用户将iPhone横向放置并在纵向视图上再次显示时,如何隐藏导航栏?
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { [[self navigationController] setNavigationBarHidden:UIInterfaceOrientationIsLandscape(toInterfaceOrientation) animated:YES]; [[UIApplication sharedApplication] setStatusBarHidden:UIInterfaceOrientationIsLandscape(toInterfaceOrientation) animated:YES]; }
这在文档中很容易找到.在UINavigationController文档中,要隐藏导航栏,请使用:
- (void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated
如果要在设备旋转时执行此操作,则需要在视图控制器方法中执行此操作(在UIViewController文档中提到):
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration