iOS:setFrame不再从viewDidLoad或viewWillAppear工作

前端之家收集整理的这篇文章主要介绍了iOS:setFrame不再从viewDidLoad或viewWillAppear工作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我更喜欢停用autoresizesSubviews,并使用setFrame放置所有的子视图.
从iOS 6开始,事情似乎发生了很大变化.
当我在viewDidLoad中的视图上调用setFrame时,没有任何效果.我从viewWillAppear中尝试过一样.

setFrame调用将在willAnimateRotationToInterfaceOrientation中工作,但最初不像iOS 5中那样调用.

有人可以澄清一下我预期的布局方式吗?

解决方法

我想你想从UIViewController布局您的视图.您是否尝试在 viewDidLayoutSubviews执行布局任务:
- (void)viewDidLayoutSubviews

根据苹果的文档:

Your view controller can override this method to make changes after the view lays out its subviews.

由于您的视图本身不会对其子视图进行布局(您不使用autosize,autolayout或layoutSubViews :)可以在此方法中执行布局任务.

然而,优雅的方式是使用自定义父UIView并执行所有布局,覆盖UIView的layoutSubViews:(除非您双方添加/删除视图).苹果公司“How View Controllers Participate in the View Layout Process”的文档报道:

Ideally,the views themselves perform all of the necessary work to reposition themselves,without requiring the view controller to participate in the process at all. However,if the view controller adds and removes views dynamically,a static layout in Interface Builder may not be possible. In this case,the view controller is a good place to control the process,because often the views themselves only have a limited picture of the other views in the scene.

猜你在找的iOS相关文章