本文介绍了旋转时,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):
- 创建于X code 7的新项目。
- 改变目标到iOS 8.4。
- 删除您的视图控制器在故事板视图,然后重新添加。
- 更改视图控制器的背景颜色,所以我们可以看到正在发生的事情。
- 嵌入导航控制器视图控制器。
- 添加导航项目视图控制器。
- 在一个UIView拖动到故事板添加中心导航项目视图。
- 添加第二个视图刚创建的一个子视图。
- 添加一个新的视图控制器到故事板,并将其设置为初始视图控制器。
- 在新的视图控制器的观点,并加载方法,嵌入导航控制器。
- 在肖像在iPad上航(8.4)运行。
- 旋转iPad上的权利,使其景观。
- 注意红色部分是如何伸出的看法。
- Create a new project in Xcode 7.
- Change the target to iOS 8.4.
- Delete your view controller's view in the storyboard, and then re-add it.
- Change the view controller's background color so we can see what is going on.
- Embed the view controller in a navigation controller.
- Add a navigation item to the view controller.
- Add a center navigation item view by dragging in a UIView to the storyboard.
- Add a second view as a subview of the one that was just created.
- Add a new view controller to the storyboard and set it as the initial view controller.
- In the new view controller's view did load method, embed the navigation controller using auto layout.
- Run on an iPad Air (8.4) in portrait.
- Rotate the iPad to the right so that it is in landscape.
- 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 theflexibleMax...
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 toYES
rather thanNO
. 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 setstranslatesAutoresizingMaskIntoConstraints=YES
, therefore, instead of trying to set up constraints, simply keep translatesAutoresizingMaskIntoConstraints set to YES, and set thechildView.frame = parentView.bounds
, to mimic the storyboard embedding behavior. (Note, you can also see that by default the storyboard will have the embedded view'sautoresize
set toW+H
, so you should ensure that your view has that set.)
这篇关于旋转时,iPad的视图控制器不一直延伸到右侧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!