項目中一般都會用到 TabBar 這個控件,需求是 TabBar在主界面正常顯示,但Push到下一級界面時則需要隱藏,Pop回來的時候又需要顯示。1、如下代碼代碼雖然能實現功能,但其操作繁瑣又無動畫效果,一般不用在此場合。
self.tabBarController.tabBar.hidden = YES;2、一般使用這種
self.hidesBottomBarWhenPushed = YES;注意:第2種一定要寫對代碼的位置,寫的不對就會出現Pop回來沒有TabBar的情況。
舉例說明:比如現在要實現 從 ViewController1 Push到 ViewController2,在 ViewController2隱藏 TabBar的效果。我們可以在 ViewController1中這如下這樣寫,就可以實現其效果。
ViewController2 *VC2 = [[ViewController2 alloc] init]; VC2.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:VC2 animated:YES];3、在push之后加上self.hidesBottomBarWhenPushed = NO;4、在tabbarController上面裝載新的navgationController,不要跟主控制器的navgation是同一個navgation,也就是說tabbarController可以不是window的rootViewController,但是tabbarController上面每個選項都要有自己單獨的(自己是這種情況)- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.hidesBottomBarWhenPushed = YES;
}
return self;
}
新聞熱點
疑難解答