我们拿从“rootVC” push 到 “pushVC”控制台输出的调用时序以及对应控制器的view的safeAreaInsets的变化
- loadView()---Optional("pushVC")
---UIEdgeInsets(top: 0.0, left: 0.0, bottom: 0.0, right: 0.0) - viewDidLoad()---Optional("pushVC")
---UIEdgeInsets(top: 0.0, left: 0.0, bottom: 0.0, right: 0.0) - willMove(toParentViewController:)---Optional("pushVC")
---UIEdgeInsets(top: 0.0, left: 0.0, bottom: 0.0, right: 0.0) - viewWillDisappear---Optional("rootVC")
---UIEdgeInsets(top: 44.0, left: 0.0, bottom: 34.0, right: 0.0) - viewWillAppear---Optional("pushVC")
---UIEdgeInsets(top: 0.0, left: 0.0, bottom: 0.0, right: 0.0) - viewSafeAreaInsetsDidChange()---Optional("pushVC")
---UIEdgeInsets(top: 44.0, left: 0.0, bottom: 34.0, right: 0.0) - viewWillLayoutSubviews()---Optional("pushVC")(视图布局改变时调用)
---UIEdgeInsets(top: 44.0, left: 0.0, bottom: 34.0, right: 0.0) - viewDidLayoutSubviews()---Optional("pushVC")(视图布局改变时调用)
---UIEdgeInsets(top: 44.0, left: 0.0, bottom: 34.0, right: 0.0) - viewWillLayoutSubviews()---Optional("pushVC")
---UIEdgeInsets(top: 44.0, left: 0.0, bottom: 34.0, right: 0.0) - viewDidLayoutSubviews()---Optional("pushVC")
---UIEdgeInsets(top: 44.0, left: 0.0, bottom: 34.0, right: 0.0) - viewDidAppear---Optional("pushVC")
---UIEdgeInsets(top: 44.0, left: 0.0, bottom: 34.0, right: 0.0) - viewDidDisappear---Optional("rootVC")
---UIEdgeInsets(top: 44.0, left: 0.0, bottom: 34.0, right: 0.0) - didMove(toParentViewController:)---Optional("pushVC")
---UIEdgeInsets(top: 44.0, left: 0.0, bottom: 34.0, right: 0.0)
注意:
viewWillLayoutSubviews和viewDidLayoutSubviews调用时机:
1、init初始化不会触发layoutSubviews
2、addSubview会触发layoutSubviews
3、设置view的Frame会触发layoutSubviews,当然前提是frame的值设置前后发生了变化
4、滚动一个UIScrollView会触发layoutSubviews
5、旋转Screen会触发父UIView上的layoutSubviews事件
6、改变一个UIView大小的时候也会触发父UIView上的layoutSubviews事件