如何隐藏UITabBar?

问题描述 投票:40回答:4

在我的应用中,我有一个标签栏。在某些视图中,我也有一个工具栏。因此,当我使用工具栏进入那些视图时,它看起来很丑-视图底部有两个条。我认为这是进入这些特定视图时隐藏标签栏的最佳解决方案。但是我只是想不出正确的方法。我试图将UITabBarController的tabBar隐藏属性设置为YES,但是它不起作用。而且我也尝试以任何观点做以下事情:

self.hidesBottomBarWhenPushed = YES;

但是它也不起作用。

针对这种情况的正确解决方案是什么?我不想在任何视图上都有2条。

ios iphone cocoa-touch uikit uitabbar
4个回答
67
投票

您必须在将要推送的控制器上将hidesBottomBarWhenPushed属性设置为YES,而不是将其设置为UITabBarController。

otherController.hidesBottomBarWhenPushed = YES;
[navigationController pushViewController: otherController animated: TRUE];

或者您可以在首次初始化要推送的控制器时设置属性。


13
投票

接口生成器在选项卡栏中嵌入了用于视图控制器的复选框-按下时隐藏底部栏。在简单的情况下,无需立即通过代码进行操作。

对于@Micah

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS91OW91My5wbmcifQ==” alt =“隐藏下推按钮。”>


10
投票

请勿使用此解决方案!

BOOL hiddenTabBar;
UITabBarController *tabBarController;

- (void) hideTabBar {

     [UIView beginAnimations:nil context:NULL];
     [UIView setAnimationDuration:0.4];
     for(UIView *view in tabBarController.view.subviews)
     {
          CGRect _rect = view.frame;
          if([view isKindOfClass:[UITabBar class]])
          {
               if (hiddenTabBar) {
                    _rect.origin.y = [[UIScreen mainScreen] bounds].size.height-49;
                    [view setFrame:_rect];
               } else {
                    _rect.origin.y = [[UIScreen mainScreen] bounds].size.height;
                    [view setFrame:_rect];
               }
          } else {
               if (hiddenTabBar) {
                    _rect.size.height = [[UIScreen mainScreen] bounds].size.height-49;
                    [view setFrame:_rect];
               } else {
                    _rect.size.height = [[UIScreen mainScreen] bounds].size.height;
                    [view setFrame:_rect];
               }
          }
     }    
     [UIView commitAnimations];

     hiddenTabBar = !hiddenTabBar;
}

Source


9
投票

我也为此苦了一段时间。隐藏选项卡栏是朝正确方向迈出的一步,但后面却留有黑色矩形。诀窍是调整支持UIViewController视图的图层的大小。

我在这里编写了一个带有解决方案的小演示:

https://github.com/tciuro/FullScreenWithTabBar

我希望这会有所帮助!

© www.soinside.com 2019 - 2024. All rights reserved.