demo地址 github.com/aberror/Lif…
1.运行工程,调用顺序Log打印如下:
2020-05-22 19:00:34.992881+0800 LifeCircleDemo[39467:385142] initWithCoder:
2020-05-22 19:00:35.000910+0800 LifeCircleDemo[39467:385142] loadViewIfNeeded
2020-05-22 19:00:35.002142+0800 LifeCircleDemo[39467:385142] loadView
2020-05-22 19:00:35.002350+0800 LifeCircleDemo[39467:385142] viewDidLoad
2020-05-22 19:00:35.002783+0800 LifeCircleDemo[39467:385142] viewWillAppear:
2020-05-22 19:00:35.004599+0800 LifeCircleDemo[39467:385142] viewWillLayoutSubviews
2020-05-22 19:00:35.004699+0800 LifeCircleDemo[39467:385142] viewDidLayoutSubviews
2020-05-22 19:00:35.052276+0800 LifeCircleDemo[39467:385142] viewDidAppear:
2. push 进一个新的视图控制器,然后再返回Log打印如下:
2020-05-22 19:00:36.277880+0800 LifeCircleDemo[39467:385142] viewWillDisappear:
2020-05-22 19:00:36.815525+0800 LifeCircleDemo[39467:385142] viewDidDisappear:
2020-05-22 19:00:46.782301+0800 LifeCircleDemo[39467:385142] viewWillAppear:
2020-05-22 19:00:46.782417+0800 LifeCircleDemo[39467:385142] loadViewIfNeeded
2020-05-22 19:00:47.287954+0800 LifeCircleDemo[39467:385142] viewDidAppear:
3.方法注释说明(官方文档)
initWithCoder
- The designated initializer. If you subclass UIViewController, you must call the super implementation of this method, even if you aren't using a NIB. (As a convenience, the default init method will do this for you, and specify nil for both of this methods arguments.) In the specified NIB, the File's Owner proxy should have its class set to your view controller subclass, with the view outlet connected to the main view. If you invoke this method with a nil nib name, then this class' -loadView method will attempt to load a NIB whose name is the same as your view controller's class. If no such NIB in fact exists then you must either call -setView: before -view is invoked, or override the -loadView method to set up your views programatically.
loadViewIfNeeded
- Loads the view controller's view if it has not already been set.
loadView
- This is where subclasses should create their custom view hierarchy if they aren't using a nib. Should never be called directly.
viewDidLoad
- Called after the view has been loaded. For view controllers created in code, this is after -loadView. For view controllers unarchived from a nib, this is after the view is set.
viewWillAppear
- Called when the view is about to made visible. Default does nothing
viewWillLayoutSubviews
- Called just before the view controller's view's layoutSubviews method is invoked. Subclasses can implement as necessary. The default is a nop.
viewDidLayoutSubviews
- Called just after the view controller's view's layoutSubviews method is invoked. Subclasses can implement as necessary. The default is a nop.
viewDidAppear
- Called when the view has been fully transitioned onto the screen. Default does nothing
viewWillDisappear
- Called when the view is dismissed, covered or otherwise hidden. Default does nothing
viewDidDisappear
- Called after the view was dismissed, covered or otherwise hidden. Default does nothing