究竟viewDidLayoutSubviews是什么? [英] What's exactly viewDidLayoutSubviews?

查看:90
本文介绍了究竟viewDidLayoutSubviews是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读UIViewControllerviewDidLayoutSubviews的描述:

被调用以通知视图控制器其视图刚刚布局了其子视图[...]但是,被调用的此方法并不表示该视图子视图的各个布局已被调整.daccess-ods.un.org daccess-ods.un.org每个子视图负责调整自己的布局[...].

Called to notify the view controller that its view has just laid out its subviews [...] However, this method being called does not indicate that the individual layouts of the view's subviews have been adjusted. Each subview is responsible for adjusting its own layout [...].

对我来说,这意味着:在子视图的布局完成时调用,但实际上并非如此".那么viewDidLayoutSubviews的真正背后是什么?

For me, it means: "Called when the layout of subviews is complete, but actually this is not true". So what's really behind viewDidLayoutSubviews?

推荐答案

当ViewControllers视图的边界发生变化时,在更改子视图的位置和大小后将调用此方法.

When bounds change for a ViewControllers View, this method is called after the positions and sizes of the subviews have changed.

  1. 因此,这是我们在布局了子视图之后但在屏幕上不可见之前进行更改以进行查看的机会.

  1. So this is our chance to make changes to view after it has laid out its subviews, but before it is visible on screen.

任何必须根据范围进行的更改,我们都可以在此处执行,而不能在ViewDidLoad或ViewWillAppear中进行.

Any changes that depending on bounds has to be done, we can do here and not in ViewDidLoad or ViewWillAppear.

而ViewDidLoad& ViewWillAppear,视图的框架和边界为 尚未完成.因此,当AutoLayout完成后,便可以修复mainView和 是子视图,称为此方法.

While ViewDidLoad & ViewWillAppear, the frame and bounds of a view are not finalised. So when AutoLayout has done it's job of fixing mainView and it's subviews, this method is called.

使用自动布局时,框架不会每次都调用layoutSubviews.在这种情况下称为这种情况.

When using autolayout, framework does not call layoutSubviews every time. This is called in these cases.

  • 旋转设备:仅在父视图(响应的viewControllers主视图)上调用layoutSubview

  • Rotating a device: only calls layoutSubview on the parent view (the responding viewControllers primary view)

其自己的边界(不是框架)已更改. (仅当新值不同(包括不同的原点)时,才考虑更改边界.)

Its own bounds (not frame) changed. (The bounds are considered changed only if the new value is different, including a different origin.)

注意: 对viewDidLayoutSubviews的调用还取决于各种因素,例如自动调整大小蒙版,是否使用自动布局以及视图是否在视图层次结构中.

Note: The call for viewDidLayoutSubviews also depends on various factors like autoresize mask, using Auto-Layout or not, and whether view is in view hierarchy or not.

对于其他任何说明,请检查何时调用layoutSubviews?

For any other clarification, check When is layoutSubviews called?

这篇关于究竟viewDidLayoutSubviews是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆