ios - 在 iOS 7 上,如果最终包含在选项卡栏 Controller 中,则使用工具栏推送 Controller 会留下不可用空间的间隙

标签 ios iphone objective-c ios7 uinavigationcontroller

在我的 iOS 应用程序中,我的窗口的 rootViewController 是一个标签栏 Controller ,其层次结构如下:

  • UITabBarController
    • UINavigationController 1
      • 第一内容 Controller
    • UINavigationController 2
      • ...
    • UINavigationController 3
      • ...
    • ...

当用户点击 FirstContentController 上的某一行时,SecondController 的一个实例将被推送到其导航 Controller 上。 SecondContentController 在其 init 方法中将 hidesBottomBarWhenPushed 设置为 YES 并设置 self.navigationController.toolbarHiddenviewWillAppear: 中的 NO

在 iOS 6 中,用户将点击 FirstController 中的行,而 SecondController 将被推送到导航 Controller 上。因为它设置了 hidesBottomBarWhenPushed,所以它会隐藏标签栏,并且在过渡动画完成时,SecondController 会出现在屏幕上,并且其工具栏可见。

然而,在 iOS 7 下测试时,hidesBottomBarWhenPushed 的行为似乎发生了变化。我现在看到的是:

  • 标签栏按预期隐藏
  • 工具栏按预期出现
  • 工具栏和内容 View 之间出现了一个正好 49 像素高(标签栏高度)的不可用空间

间隙完全无法使用 - 它不响应触摸,如果我在主视图上将 clipsToBounds 设置为 YES,则不会出现任何内容。经过大量调试和检查 subview 层次结构,看起来 iOS 的自动调整大小机制将 View Controller 的 View 调整为 411 的高度(在 iPhone 5 上)。一直到工具栏应该是 460,但布局系统似乎包括一个 49 像素高的“幽灵”标签栏。

只有当 View Controller 有一个标签栏 Controller 作为其父容器时才会出现此问题。

在 iOS 7 上,如何在推送新 Controller 时让标签栏消失并且工具栏无缝滑入到位,并且仍然让 View 占据导航项和工具栏之间的整个空间?

更新

经过进一步调查,只有在 SecondController 的 edgesForExtendedLayout 设置为 UIRectEdgeNone 时才会发生这种情况。但是,除非我将该属性设置为 UIRectEdgeNone,否则 View 的框架会太长并延伸到工具栏下方,无法看到或与之交互。

最佳答案

我发现在 SecondViewController 的 viewDidLoad 中添加以下两行代码(您想隐藏 TabBar 但显示工具栏)可以解决问题。

self.extendedLayoutIncludesOpaqueBars = YES;
self.edgesForExtendedLayout = UIRectEdgeBottom;

我的SecondViewController的viewDidLoad如下:

- (void)viewDidLoad {
    [super viewDidLoad];
    // These 2 lines made the difference
    self.extendedLayoutIncludesOpaqueBars = YES;
    self.edgesForExtendedLayout = UIRectEdgeBottom;

    // The usual configuration
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    self.navigationController.navigationBar.translucent = NO;

    self.navigationController.toolbarHidden = NO;
    self.navigationController.toolbar.barStyle = UIBarStyleBlack;
    self.navigationController.toolbar.translucent = NO;
    .
    .
}

但是您需要手动修复 View 的框架,因为这会导致尺寸为 (320x504)。这意味着它甚至延伸到工具栏后面。如果这不是您关心的问题,那么这个解决方案应该可以工作。

关于ios - 在 iOS 7 上,如果最终包含在选项卡栏 Controller 中,则使用工具栏推送 Controller 会留下不可用空间的间隙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20578994/

相关文章:

ios - 我的返回数据表单 AFNetworking JSON 未正确显示

ios - 如何找出哪个类占用最多内存?

c - Obj-C 错误 : Expected expression before . .....(为什么?)

iphone - HTML 内容适合 UIWebview 而无需缩小

ios - 自定义标注(mapBox iOS sdk)

iphone - 在通用应用程序中呈现 View Controller ,iOS 4 到 6

ios - 如何分发具有开发临时性的 ios 应用程序

ios - UICollectionViewCell 以固有大小展开/折叠

iphone - 在由 CGMutablePaths 组成的 Shape 周围拖动 UIView

iphone - 如何使用 Quartz 绘制钢笔笔画?