本文介绍了旋转时,iPad的视图控制器不一直延伸到右侧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在iPad 8.4转动我的视图控制器,我的观点并没有一直延伸到右:

When I rotate my view controller on an iPad 8.4, my view doesn't extend all the way to the right:

在这个例子中,红色的看法是我的根视图控制器,它不应该是可见的。我使用嵌入的UIViewController遏制导航控制器):

Steps to reproduce problem (or try this GitHub project):


  1. 创建于X code 7的新项目。

  2. 改变目标到iOS 8.4。

  3. 删除您的视图控制器在故事板视图,然后重新添加。

  4. 更改视图控制器的背景颜色,所以我们可以看到正在发生的事情。

  5. 嵌入导航控制器视图控制器。

  6. 添加导航项目视图控制器。

  7. 在一个UIView拖动到故事板添加中心导航项目视图。

  8. 添加第二个视图刚创建的一个子视图。

  9. 添加一个新的视图控制器到故事板,并将其设置为初始视图控制器。

  10. 在新的视图控制器的观点,并加载方法,嵌入导航控制器。

  11. 在肖像在iPad上航(8.4)运行。

  12. 旋转iPad上的权利,使其景观。

  13. 注意红色部分是如何伸出的看法。

  1. Create a new project in Xcode 7.
  2. Change the target to iOS 8.4.
  3. Delete your view controller's view in the storyboard, and then re-add it.
  4. Change the view controller's background color so we can see what is going on.
  5. Embed the view controller in a navigation controller.
  6. Add a navigation item to the view controller.
  7. Add a center navigation item view by dragging in a UIView to the storyboard.
  8. Add a second view as a subview of the one that was just created.
  9. Add a new view controller to the storyboard and set it as the initial view controller.
  10. In the new view controller's view did load method, embed the navigation controller using auto layout.
  11. Run on an iPad Air (8.4) in portrait.
  12. Rotate the iPad to the right so that it is in landscape.
  13. Notice how the red portion sticks out of the view.

这是解决这个问题的事情:

Things that fix it:


  • 使用的iOS 9.0

  • 使用一部iPhone,而不是一个iPad

  • 请不要在导航项目的中心位置(一个单一的视图是好的;但鉴于内的标签,例如,会引起这种断裂)两个视图。

  • 打开为故事板的XML和更改视图控制器的视图的 autoresizingMask < autoresizingMask键=autoresizingMaskflexibleMaxX =YES flexibleMaxY =YES/> < autoresizingMask键=autoresizingMaskwidthSizable =YESheightSizable =YES/> 。 (默认情况下,当你在一个视图控制器拖到故事板,它将使用 ...可观的变体。但是,如果你删除的视图(不是的视图控制器的),然后拖动视图回视图控制器,它会使用 flexibleMax ... 的变种。)

  • 请不要使用UIViewController的遏制。

  • 如果你使用的UIViewController围堵,让故事板嵌入视图控制器。

  • 如果您使用的UIViewController遏制编程,然后确保 translatesAutoresizingMaskIntoConstraints 设置为,而不是 NO 。如果比较与嵌入视图控制器的故事板方式href=\"http://stackoverflow.com/a/27630514/35690\">自动布局方式,你会看到该故事板集 translatesAutoresizingMaskIntoConstraints = YES ,因此,而不是试图建立约束,仅保留设置为YES translatesAutoresizingMaskIntoConstraints,并设置 childView.frame = parentView.bounds ,以模仿故事板嵌入行为。 (注意,你也可以看到,默认情况下,故事板将有内嵌视图的自动调整大小设置为宽+高,所以你应该确保你的观点有集。)

  • Use iOS 9.0
  • Use an iPhone instead of an iPad
  • Don't have two views in the navigation item's center position (a single view is fine; but a label inside of a view, for example, will cause this sort of breakage).
  • Open up the XML for the storyboard and change the view controller's view's autoresizingMask from <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> to <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>. (By default when you drag in a view controller to the storyboard, it will use the ...Sizable variants. If, however, you delete the view (not the view controller), then drag a view back into the view controller, it will use the flexibleMax... variants.)
  • Don't use UIViewController containment.
  • If you do use UIViewController containment, let the storyboard embed the view controller.
  • If you do use UIViewController containment programmatically, then ensure that translatesAutoresizingMaskIntoConstraints is set to YES rather than NO. If you compare the auto layout way of embedding a view controller vs. the storyboard way of embedding a view controller, you will see that the storyboard sets translatesAutoresizingMaskIntoConstraints=YES, therefore, instead of trying to set up constraints, simply keep translatesAutoresizingMaskIntoConstraints set to YES, and set the childView.frame = parentView.bounds, to mimic the storyboard embedding behavior. (Note, you can also see that by default the storyboard will have the embedded view's autoresize set to W+H, so you should ensure that your view has that set.)

这篇关于旋转时,iPad的视图控制器不一直延伸到右侧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 12:15