自动布局和设备定位 [英] Autolayout and Device Orientation
问题描述
我在开发的支持纵向和横向模式的应用程序
。我使用自动布局来安排我的看法
。正如我一直在读很多帖子,我已经意识到,开发人员通常使用以下方法中的一种。
I am developing an application which supports portrait and landscape modes
. I am using auto layout to arrange my views
. As i have been reading many posts and i have realized that developers commonly use one among the following approaches.
1。第一种方式:
实施的UIViewController:根据设备方向updateConstraints
方法和更新限制
2。第二条本办法:
实施的UIViewController:根据设备方向viewWillLayoutSubviews
方法和更新限制
谁能告诉我什么是用最好的方法?我一直在寻找一个最佳实践自转和经销商的布局并没有什么还没有结合起来。谢谢你。
Could anyone please tell me what is the best approach to use ? I have been searching for a best practice to combine autorotation and auto layout and nothing yet. Thanks.
推荐答案
我会用这个UIViewController的方法:
I would use this UIViewController's method:
- (无效)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation时间:(NSTimeInterval)持续时间;
这是建立在所谓的旋转,并从那里调用 -setNeedsUpdateConstraints
。
如果你需要做额外的计算或管理contrainsts添加
that is called upon rotation, and call -setNeedsUpdateConstraints
from there.
If you need to do additional calculations or manage the contrainsts add
- (void)updateViewConstraints
{
[super updateViewConstraints];
// do calculations if needed, like set constants
}
这篇关于自动布局和设备定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!