旋转时隐藏导航栏

时间:2009-01-12 18:16:00

标签: cocoa-touch

我有一个带导航栏的UIView。当用户将iPhone横向放置并在纵向视图上再次显示时,如何隐藏导航栏?

3 个答案:

答案 0 :(得分:9)

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

答案 1 :(得分:7)

这在文档中很容易找到。在UINavigationController文档中,要隐藏导航栏,请使用:

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

如果要在设备旋转时执行此操作,您需要在视图控制器方法中执行此操作(在UIViewController文档中提及):

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

答案 2 :(得分:-2)

更好的方法是恕我直言使用CGAffineTransform,并将导航栏保留在原来的位置 - 就像iPhone的照片库视图一样。请参阅Jeff Lamarche的精彩介绍Demystifying CGAffineTransform。帮助了我很多。

相关问题