[英]Auto Layout = ViewWillAppear has the wrong width of the view
I am using autolayout for parts of my UI. 我正在为我的部分UI使用autolayout。 When I check the width of my view in viewWillAppear, the width has not yet updated.
当我在viewWillAppear中检查视图的宽度时,宽度尚未更新。 It gets updated after the second callback to - (void)updateViewConstraints.
它在第二次回调到 - (void)updateViewConstraints后得到更新。 The issue is I set up my parts of my UI (using spring and struts for legacy reasons) based on this width in viewWillAppear.
问题是我在viewWillAppear中根据此宽度设置了我的UI部分(由于遗留原因使用spring和struts)。 When is the good time to set up this legacy UI which takes in a width parameter ?
什么时候设置这个带有宽度参数的旧UI?
thanks 谢谢
Layout happens after viewWillAppear
returns. 在
viewWillAppear
返回后发生布局。 Do it in viewDidLayoutSubviews
(in your view controller) or in layoutSubviews
(in your custom view subclass). 在
viewDidLayoutSubviews
(在视图控制器中)或layoutSubviews
(在自定义视图子类中)中执行。 Either way, be sure to call super
first. 无论哪种方式,一定要先打
super
。
Another way is to force layout by sending [view layoutIfNeeded]
. 另一种方法是通过发送
[view layoutIfNeeded]
来强制布局。 Then you can add subviews and set their springs and struts. 然后你可以添加子视图并设置它们的弹簧和支柱。 The system will perform layout again (at its usual time) because you added subviews.
系统将再次执行布局(在通常的时间),因为您添加了子视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.