2011-06-07 57 views

回答

4

而不是將其設置在viewDidLoad中,我發現有時候這太遲了。在init中設置它或覆蓋hidesBottomBarWhenPushed返回YES以查看沒有底部工具欄的視圖。

+0

覆蓋hidesBottomBarWhenPushed是一個很好的解決方案;) – Bejil 2012-10-22 07:31:52

8

鑑於控制器A(其是在使用TabBar)中,當它的時間來呈現B(沒有的TabBar想要的):

self.hidesBottomBarWhenPushed = YES; // hide the tabBar when pushing B 
[self.navigationController pushViewController:viewController_B animated:YES]; 
self.hidesBottomBarWhenPushed = NO; // for when coming Back to A 

鑑於控制器B,當談到時間呈現C(的TabBar再次希望):

self.hidesBottomBarWhenPushed = NO; // show the tabbar when pushing C 
[self.navigationController pushViewController:viewController_C animated:YES]; 
self.hidesBottomBarWhenPushed = YES; // for when coming Back to B 
0

從hidesBottomBarWhenPushed文檔:

如果是,底欄保持隱藏,直到VIE w控制器從棧中彈出 。

這意味着,如果你不一定知道的視圖控制器將被推送的順序排列,你需要從堆棧中的所有視圖控制器有其hidesBottomBarWhenPushed設置爲false除了topViewController。

所以我推新視圖控制器我設置其屬性hidesBottomBarWhenPushed根據需要做之前

  1. 也推動self.hidesBottomBarWhenPushed確保整個堆棧,直到下一次會有我之前集合其屬性彈出之前設置爲false
  2. ,這是當我檢查的TabBar應顯示與否,並更新其hidesBottomBarWhenPushed

下面是1一些代碼,2)

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
    self.hidesBottomBarWhenPushed = false 

    if (segue.identifier == "MyViewControllerWhoHidesTabBar") { 
     let viewController: MyViewControllerWhoShowsTabBar = segue.destinationViewController as! MyViewControllerWhoShowsTabBar 
     viewController.hidesBottomBarWhenPushed = true 
    } 
     // rest of implementation.... 
} 

3)我重寫後退按鈕動作

func backButtonClick(sender:UIButton!) { 
    let viewControllers = self.navigationController!.viewControllers 
    if let vc = viewControllers[viewControllers.count-2] as? MyViewController { 
     if vc.isKindOfPageYouDontWannaShowTheTabBar() == true { 
     vc.hidesBottomBarWhenPushed = true 
     } 
    } 
    navigationController?.popViewControllerAnimated(true) 
    }