2009-01-12 143 views
5

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

回答

6

这在文档中很容易找到。在UINavigationController的文档,隐藏的导航栏,您可以使用:

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

如果你想这样做,当设备旋转时,你会想这样做在您的视图控制器方法(在UIViewController中提到的文档):

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

如果希望导航栏永远不应该隐藏方向改变时,但每当我切换到风景时,它总是隐藏,这段代码也不起作用。请帮帮我 – 2017-05-28 09:06:52

-2

一种更好的方式恕我直言,是使用CGAffineTransform,并留下了导航栏的地方是 - 像iPhone的照片库视图。见Jeff Lamarche的优秀介绍Demystifying CGAffineTransform。帮助了我很多。

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