2009-05-02 79 views
39

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

self.hidesBottomBarWhenPushed = YES; 

但它没有起作用。

这种情况的正确解决方案是什么?任何观点我都不想有2个酒吧。

谢谢。

回答

67

你必须在控制器上设置hidesBottomBarWhenPushed属性为YES,而不是UITabBarController。

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

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

+1

我有所述的UITabBarController可以呈现3个视图控制器。在第二个视图控制器上,我在`initWithNibName:bundle:`中放置了`self.hidesBottomBarWhenPushed = YES`。当我测试第二个视图控制器时,UITabBar仍然存在。 – JoJo 2011-09-27 22:10:55

+1

使用ios7尝试使用新项目 - 无效 – Adam 2014-01-02 12:40:34

+0

当我回到屏幕时,我在标签栏顶部有一个黑色空间。 – manonthemoon 2016-05-28 08:41:08

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

+1

使用自定义选项卡栏(ALTabBar)。这一个为我工作。而不是支持4“屏幕,我已经将480更改为[[UIScreen mainScreen]边界] - > size.height – 2013-10-26 10:16:57

8

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

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

https://github.com/tciuro/FullScreenWithTabBar

我希望这有助于!

11

界面构建器的视图控制器复选框嵌入在标签栏 - 隐藏底部栏在推。在简单的情况下,现在不需要通过代码来完成。

对于@Micah

Hide bottom bar on push.