如何隱藏uitabbarcontroller我有問題UITabBarController。在我的應(yīng)用程序中,我想隱藏它但沒有使用,hidesBottomBarWhenPushed因?yàn)槲蚁腚[藏它而不是當(dāng)我推它時(shí)。例如,我想在我的應(yīng)用程序中按“隱藏”按鈕時(shí)隱藏它。我在谷歌閱讀了很多文章,但我無法知道如何做到這一點(diǎn)。
3 回答

慕姐4208626
TA貢獻(xiàn)1852條經(jīng)驗(yàn) 獲得超7個(gè)贊
我從我的工作代碼中粘貼這個(gè)...你可以調(diào)用這些方法來隱藏和顯示tabbarcontroller ....只需將tabbarcontroller實(shí)例傳遞給這些函數(shù)..
// Method call[self hideTabBar:self.tabBarController];
// Method implementations- (void)hideTabBar:(UITabBarController *) tabbarcontroller{ [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; for(UIView *view in tabbarcontroller.view.subviews) { if([view isKindOfClass:[UITabBar class]]) { [view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)]; } else { [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)]; } } [UIView commitAnimations]; }- (void)showTabBar:(UITabBarController *) tabbarcontroller{ [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; for(UIView *view in tabbarcontroller.view.subviews) { NSLog(@"%@", view); if([view isKindOfClass:[UITabBar class]]) { [view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)]; } else { [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)]; } } [UIView commitAnimations]; }

智慧大石
TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超3個(gè)贊
改進(jìn)的Setomidor對(duì)橫向,縱向和iPad工作的回答(320和480值僅適用于iPhone)。
- (void) hideTabBar:(UITabBarController *) tabbarcontroller { CGRect screenRect = [[UIScreen mainScreen] bounds]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; float fHeight = screenRect.size.height; if( UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) ) { fHeight = screenRect.size.width; } for(UIView *view in tabbarcontroller.view.subviews) { if([view isKindOfClass:[UITabBar class]]) { [view setFrame:CGRectMake(view.frame.origin.x, fHeight, view.frame.size.width, view.frame.size.height)]; } else { [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)]; view.backgroundColor = [UIColor blackColor]; } } [UIView commitAnimations];}- (void) showTabBar:(UITabBarController *) tabbarcontroller { CGRect screenRect = [[UIScreen mainScreen] bounds]; float fHeight = screenRect.size.height - tabbarcontroller.tabBar.frame.size.height; if( UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) ) { fHeight = screenRect.size.width - tabbarcontroller.tabBar.frame.size.height; } [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; for(UIView *view in tabbarcontroller.view.subviews) { if([view isKindOfClass:[UITabBar class]]) { [view setFrame:CGRectMake(view.frame.origin.x, fHeight, view.frame.size.width, view.frame.size.height)]; } else { [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)]; } } [UIView commitAnimations]; }
還修改了代碼以處理iOS 6中引入的更改,并更改了UIDevice方向,并確保即使設(shè)備背面也能正常工作。

素胚勾勒不出你
TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超9個(gè)贊
在按鈕的操作方法中:
[self.tabBarController.tabBar setHidden:YES];
- 3 回答
- 0 關(guān)注
- 938 瀏覽
添加回答
舉報(bào)
0/150
提交
取消