我在使用隱藏按鈕時遇到了麻煩,當按下按鈕時,我會將三個控制器(A,B和C)推入導航控制器,並且我想在顯示B時隱藏底部的選項卡欄(並且A是其中一個標籤控制器)如何使用hidesBottomBarWhenPushed如果我想隱藏只有一種控制器的tabbar?
有沒有人有想法?
我在使用隱藏按鈕時遇到了麻煩,當按下按鈕時,我會將三個控制器(A,B和C)推入導航控制器,並且我想在顯示B時隱藏底部的選項卡欄(並且A是其中一個標籤控制器)如何使用hidesBottomBarWhenPushed如果我想隱藏只有一種控制器的tabbar?
有沒有人有想法?
而不是將其設置在viewDidLoad中,我發現有時候這太遲了。在init中設置它或覆蓋hidesBottomBarWhenPushed返回YES以查看沒有底部工具欄的視圖。
鑑於控制器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
從hidesBottomBarWhenPushed文檔:
如果是,底欄保持隱藏,直到VIE w控制器從棧中彈出 。
這意味着,如果你不一定知道的視圖控制器將被推送的順序排列,你需要從堆棧中的所有視圖控制器有其hidesBottomBarWhenPushed設置爲false除了topViewController。
所以我推新視圖控制器我設置其屬性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)
}
覆蓋hidesBottomBarWhenPushed是一個很好的解決方案;) – Bejil 2012-10-22 07:31:52