UIViewController appear disappear调用时机

首次显示一个ViewController时,调用顺序如下:

viewWillAppear:

viewWillLayoutSubviews

viewDidLayoutSubviews

viewDidAppear


当VC1 切换到VC2时,调用顺序如下:

VC1:viewWillDisappear:

VC2:viewWillAppear:

VC2:viewWillLayoutSubviews

VC2:viewDidLayoutSubviews

VC2:viewDidAppear:

VC1:viewDidDisappear:


其中如果viewWillLayoutSubviews和viewDidLayoutSubviews调用过之后,那么如果ViewController的frame没有发生过改变,那么是不会再次调用的。比如从VC2在返回到VC1时,VC1只会调用appear和disappear相关函数,willLayout和didLayout是不会被调用的。

你可能感兴趣的:(UIViewController appear disappear调用时机)