如何隱藏uitabbarcontroller我有問題UITabBarController。在我的應用程序中,我想隱藏它但沒有使用,hidesBottomBarWhenPushed因為我想隱藏它而不是當我推它時。例如,我想在我的應用程序中按“隱藏”按鈕時隱藏它。我在谷歌閱讀了很多文章,但我無法知道如何做到這一點。
3 回答

慕姐4208626
TA貢獻1852條經驗 獲得超7個贊
我從我的工作代碼中粘貼這個...你可以調用這些方法來隱藏和顯示tabbarcontroller ....只需將tabbarcontroller實例傳遞給這些函數..
// 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貢獻1946條經驗 獲得超3個贊
改進的Setomidor對橫向,縱向和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方向,并確保即使設備背面也能正常工作。
- 3 回答
- 0 關注
- 939 瀏覽
添加回答
舉報
0/150
提交
取消