40

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

self.hidesBottomBarWhenPushed = YES;

但它也没有奏效。

这种情况的正确解决方案是什么?我不想在任何视图中有 2 个酒吧。

4

5 回答 5

68

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

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

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

于 2009-05-02T22:14:39.520 回答
13

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

对于@Micah

按下时隐藏底部栏。

于 2013-04-11T07:31:28.900 回答
9

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

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

https://github.com/tciuro/FullScreenWithTabBar

我希望这有帮助!

于 2012-05-06T20:59:44.437 回答
9

不要使用这个解决方案!

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;
}

资源

于 2010-01-04T00:40:02.297 回答
0

没有内置方法可以隐藏当前视图的选项卡栏。

hidesBottomBarWhenPushed您可以在使用变量推送视图时隐藏它。

如果要在当前视图中隐藏标签栏,可以执行以下操作:

要点在这里

请注意,UIKit 似乎将标签栏带回应用程序恢复。所以你必须订阅通知UIApplication.didBecomeActiveNotification并调用上述函数。

于 2021-01-14T02:53:49.493 回答