隐藏UITabBar?

时间:2009-05-02 21:38:23

标签: iphone cocoa-touch

在我的应用中,我有一个标签栏。在某些视图中我也有一个工具栏。因此,当我使用工具栏来查看这些视图时,它看起来很难看 - 视图底部有两个条形图。我认为在输入特定视图时隐藏标签栏是最佳解决方案。 但我无法弄清楚如何以正确的方式做到这一点。我试图将UITabBarController的tabBar隐藏属性设置为YES,但它不起作用。我也试图以任何方式做以下事情:

self.hidesBottomBarWhenPushed = YES;

但它也不起作用。

这种情况的正确解决方案是什么?我不想在任何视野中都有2个小节。

谢谢。

4 个答案:

答案 0 :(得分:67)

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

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

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

答案 1 :(得分:12)

界面构建器具有嵌入在选项卡栏中的视图控制器的复选框 - 在推送时隐藏底栏。在简单的情况下,现在无需通过代码完成。

对于@Micah

Hide bottom bar on push.

答案 2 :(得分: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

答案 3 :(得分:9)

我这一段时间也很挣扎。隐藏标签栏是向右方向迈出的一步,但后面留下一个黑色矩形。诀窍是调整支持UIViewController视图的层的大小。

我在这里写了一个小型演示解决方案:

https://github.com/tciuro/FullScreenWithTabBar

我希望这有帮助!