为什么叫viewdidlayoutsubviews多次?(Why viewdidlayoutsubviews call multiple times?)
I'm developing iOS Universal App on Swift,using auto layout and support only portrait.
I found UIViewController#viewdidlayoutsubviews called multiple times. Instead, viewDidLoad ONLY call once on starting up MyApp's UIViewController.
Why viewdidlayoutsubviews call multiple times? Constraints on each UIView(UIButtons,UITextFields etc..) will perform in order?
Any Information will be appreciated.
解决方案
LoadView is only called one: when the view needs to be loaded.
LayoutSubviews, however, is called once per run loop on any view that has had setNeedsLayout or setNeedsDisplayInRect called on it - this includes whenever a subview has been added to the view, scrolling, resizing, etc.
See this link for more information. It uses Objective-C, but the information still holds.
我对雨燕的iOS开发通用应用程序,使用自动布局和仅支持肖像。
我发现的UIViewController#viewdidlayoutsubviews 多次调用。相反, viewDidLoad中仅在启动MyApp的的UIViewController调用一次。
为什么viewdidlayoutsubviews多次调用?每个UIView的约束(UIButtons,UITextFields等)会按顺序执行?
任何信息将AP preciated。
解决方案
的loadView 只能称为一种:当视图需要加载
LayoutSubviews ,但是,每次运行循环调用一次上有过任何视图 setNeedsLayout 或 setNeedsDisplayInRect 调用它 - 这包括每当一个子视图已被添加到视图,滚动,缩放,等