2009-05-02 76 views
39

在我的應用程序中,我有一個標籤欄。而在一些觀點中,我也有一個工具欄。所以當我用工具欄來看這些視圖時,它看起來很醜 - 視圖底部有兩個橫條。我認爲這是一個在輸入特定視圖時隱藏標籤欄的最佳解決方案。 但我只是無法弄清楚如何以正確的方式做到這一點。我試圖將UITabBarController的tabBar隱藏屬性設置爲YES,但它不起作用。而且我也試圖以任何觀點來做以下事情:隱藏UITabBar?

self.hidesBottomBarWhenPushed = YES; 

但它沒有起作用。

這種情況的正確解決方案是什麼?任何觀點我都不想有2個酒吧。

謝謝。

回答

67

你必須在控制器上設置hidesBottomBarWhenPushed屬性爲YES,而不是UITabBarController。

otherController.hidesBottomBarWhenPushed = YES; 
[navigationController pushViewController: otherController animated: TRUE]; 

或者,您可以在首次初始化要推送的控制器時設置屬性。

+1

我有所述的UITabBarController可以呈現3個視圖控制器。在第二個視圖控制器上,我在`initWithNibName:bundle:`中放置了`self.hidesBottomBarWhenPushed = YES`。當我測試第二個視圖控制器時,UITabBar仍然存在。 – JoJo 2011-09-27 22:10:55

+1

使用ios7嘗試使用新項目 - 無效 – Adam 2014-01-02 12:40:34

+0

當我回到屏幕時,我在標籤欄頂部有一個黑色空間。 – manonthemoon 2016-05-28 08:41:08

10

請勿使用此解決方案!

BOOL hiddenTabBar; 
UITabBarController *tabBarController; 

- (void) hideTabBar { 

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.4]; 
    for(UIView *view in tabBarController.view.subviews) 
    { 
      CGRect _rect = view.frame; 
      if([view isKindOfClass:[UITabBar class]]) 
      { 
       if (hiddenTabBar) { 
        _rect.origin.y = [[UIScreen mainScreen] bounds].size.height-49; 
        [view setFrame:_rect]; 
       } else { 
        _rect.origin.y = [[UIScreen mainScreen] bounds].size.height; 
        [view setFrame:_rect]; 
       } 
      } else { 
       if (hiddenTabBar) { 
        _rect.size.height = [[UIScreen mainScreen] bounds].size.height-49; 
        [view setFrame:_rect]; 
       } else { 
        _rect.size.height = [[UIScreen mainScreen] bounds].size.height; 
        [view setFrame:_rect]; 
       } 
      } 
    }  
    [UIView commitAnimations]; 

    hiddenTabBar = !hiddenTabBar; 
} 

Source

+1

使用自定義選項卡欄(ALTabBar)。這一個爲我工作。而不是支持4「屏幕,我已經將480更改爲[[UIScreen mainScreen]邊界] - > size.height – 2013-10-26 10:16:57

8

我也有這個掙扎了一段時間。隱藏標籤欄是朝正確方向邁出的一步,但在後面留下黑色矩形。訣竅是調整支持UIViewController視圖的圖層大小。

我在這裏寫了一個小演示了一個解決方案:

https://github.com/tciuro/FullScreenWithTabBar

我希望這有助於!

11

界面構建器的視圖控制器複選框嵌入在標籤欄 - 隱藏底部欄在推。在簡單的情況下,現在不需要通過代碼來完成。

對於@Micah

Hide bottom bar on push.