【问题标题】:Hiding Tabbar still occupy Space?隐藏标签栏还占用空间?
【发布时间】:2011-03-28 13:57:47
【问题描述】:

我正在创建一个导航基础应用程序。我也需要显示一个标签栏。

我的 mainWindow.xib 包含:

  • UINavigationController,
  • UITabBarController

UITabBarController 有三个UINavigationController

在基于条件的算法中,我正在显示导航和 TabBar。

它运作良好。当我想移动 TabBar 的任何内部视图时会出现问题:它在那里显示 navigationBar(我需要的),但它也显示 TabBar。我想删除所有内部视图的 TabBar。当我隐藏标签栏时,它仍然占据视图底部的空间。我曾尝试重置 View 和 Window 的框架,但没有任何帮助。

如何隐藏 tabBar 并在我的视图中使用它的空间?

我使用的逻辑是否正确?如果不是,请告诉如何更正。如果有教程就更好了。

【问题讨论】:

    标签: iphone uinavigationcontroller uitabbarcontroller


    【解决方案1】:

    你可以试试这个:

    yourInnerViewController.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:yourInnerViewController animated:YES];
    

    【讨论】:

    • 这正是我想要的。谢谢@sycx。请让我知道,苹果不禁止这种方法。谢谢
    • 别担心,这是一般用法,在View Controller Programming Guide中介绍
    • 我在 swift 中遇到了同样的问题。你是如何在 Swift 中做到这一点的?
    • 我在 viewWillAppear 中使用 `self.tabBarController?.tabBar.hidden = true' 和 'self.hidesBottomBarWhenPushed = true' 来隐藏标签栏。它大部分时间都有效,但并非一直有效。此外,它不是很顺利。每次 ViewController 出现时,tabbasr 曾经所在的底部空白区域需要一段时间才能消失。
    【解决方案2】:

    答案是你不能,并且试图强制它会破坏苹果的 HIG,他们很可能会拒绝你的应用。

    我解决它的方法是使用[self presentModalViewController:animated:] 而不是[self.navigationController pushViewController:animated:]

    我知道这很烦人,但有一个标签栏控制器可以在应用程序的各个部分之间切换。因此,它在其中的导航控制器的上下文之外提供了功能,因此不能(正确地)从这些导航控制器之一中隐藏。

    【讨论】:

    • 感谢 Thomas,但使用 presentModalViewController 我也不能使用导航控制器。
    • 使用 presentModalViewController 你可以传入一个新的导航控制器。
    • 那么self.tabBarController?.tabBar.hidden = true的目的是什么