在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

查看:98
本文介绍了在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


      • ...


      • ...

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

      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 's行为似乎已经改变。我现在看到的是:

      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?

      UPDATE

      经过进一步调查后,只有在SecondController的 edgesForExtendedLayout 设置为 UIRectEdgeNone <时才会发生这种情况/ code>。但是,除非我将该属性设置为 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.

      推荐答案

      取消选中在推送时隐藏底部栏并设置自动约束,就好像有一个标签栏一样。然后在控制器的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或隐藏将使标签栏无效)现在,autoconstaraints将确保您的视图正确显示,标签栏高度为零。

      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天全站免登陆