2009-01-12 199 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]; 
}