viewWillLayoutSubviews

1.切换横竖屏时,让一个控件的位置改变,就会调用这个方法,viewWillLayoutSubviews.

2.官门文档解释

When a view'€™s bounds change, the view adjusts the position of its subviews. Your view controller can override this method to make changes before the view lays out its subviews. The default implementation of this method does nothing.

当一个视图的€™的边界变化,在视图调整其子视图的位置。你的视图控制器可以重写此方法以在视图布局它的子视图更改。该方法的默认实现不执行任何操作。

You may override this method in a subclass in order to add constraints to the view or its subviews. If you override this method, your implementation must invoke super’s implementation.

你可能在为一类约束添加到视图或它的子视图重写这个方法。如果你重写这个方法,您的实现必须调用超的实现。

3.例子

To use a top layout guide without using constraints, obtain the guide’€™s position relative to the top bound of the containing view. In the case of using a view controller subclass, obtain the numbers you need as follows:

使用上面的布局指南没有使用限制,获得指导的€™的位置相对于顶部的含视图绑定。在使用一个视图控制器类的情况下,获得你需要的号码如下:
- (void) viewDidLayoutSubviews {
CGRect viewBounds = self.view.bounds;
CGFloat topBarOffset = self.topLayoutGuide.length;
}

你可能感兴趣的:(布局与屏幕适配)