在 iOS 7 上,如果最终包含在选项卡栏控制器中,则使用工具栏推送控制器会留下不可用空间的间隙 [英] On iOS 7, pushing a controller with a toolbar leaves a gap of unusable space if it's ultimately contained within a tab bar controller

查看:14
本文介绍了在 iOS 7 上,如果最终包含在选项卡栏控制器中,则使用工具栏推送控制器会留下不可用空间的间隙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In my iOS app, my window's rootViewController is a tab bar controller with the a hierarchy like this:

  • UITabBarController
    • UINavigationController 1
      • 第一内容控制器
      • ...
      • ...

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

      When the user taps a certain row on FirstContentController, an instance of SecondController will be pushed onto its navigation controller. SecondContentController sets hidesBottomBarWhenPushed to YES in its init method and sets self.navigationController.toolbarHidden to NO in viewWillAppear:.

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

      In iOS 6, the user would tap the row in FirstController and SecondController would get pushed onto the nav controller. Because it has hidesBottomBarWhenPushed set, it would hide the tab bar and, by the time the transition animation was complete, SecondController would be on the screen with its toolbar visible.

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

      However, when testing this under iOS 7, hidesBottomBarWhenPushed's behavior seems to have changed. What I see now is:

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

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

      The gap is completely unusable - it doesn't respond to touches and if i set clipsToBounds to YES on the main view, nothing draws there. After a lot of debugging and examining subview hierarchies, it looks like iOS's autosizing mechanism resizes the view controller's view to a height of 411 (on the iPhone 5). It should be 460 to reach all the way down to the toolbar, but the layout system seems to be including a "ghost" 49-pixel-tall tab bar.

      只有当视图控制器有一个标签栏控制器作为其父容器时才会出现此问题.

      This problem only occurs if the view controller has a tab bar controller as one if its parent containers.

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

      On iOS 7, how can I have the tab bar disappear and a toolbar seamlessly slide into place when a new controller is pushed, and still have the view take up the entire space between the navigation item and the toolbar?

      更新

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

      After further investigation, this only happens if SecondController's edgesForExtendedLayout is set to UIRectEdgeNone. However, unless I set that property to UIRectEdgeNone, the view's frame is too long and extends under the toolbar, where it can't be seen or interacted with.

      推荐答案

      取消选中Hide bottoms bar on push"并设置你的自动约束,就好像有一个标签栏一样.然后在要隐藏系统标签栏的控制器的ViewDidLoad"中,输入以下代码.

      Uncheck "Hide bottoms bars on push" and set your autoconstraints as if there is a tab bar. Then in "ViewDidLoad" of the controller you want to hide the system tab bar, put the following code.

      [self.tabBarController.tabBar setFrame:CGRectZero];
      

      这确保标签栏仍然接受用户交互但对用户不可见.(其他替代方法,例如将其设置为 0 alpha 或隐藏将呈现标签栏无用)现在自动约束将确保您的视图正确显示,标签栏高度为零.

      This makes sure the tab bar still accepts user interaction yet not visible to users. (other alternatives such as setting it 0 alpha or hidden will render tab bar useless) Now the autoconstaraints will make sure your view displays correctly with the tab bar height as zero.

      这篇关于在 iOS 7 上,如果最终包含在选项卡栏控制器中,则使用工具栏推送控制器会留下不可用空间的间隙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆