1 Responsibilities
1.1 UIViewController duties
UIView, event manager, responsible for creating dependency.
1.2 UIView duties
-
It is a sub-view event, CALayer managers.
-
Process layout.
2 layout
In most cases, it is AutoLayout 自上而下
layout, the tree view, the parent node of setting constraints subviews.
So long as we know the roots of the frame can draw a tree view of the whole grain.
In some cases, the lower layout will affect the upper, such as automatic tableView estimates, the new circle of friends reply.
At this time, the tree view child nodes need to tell their parent node to re-calculate their own constraints, and refresh the layout.
3 code organization
3.1 For view
-
initWithFrame in
Assembly subview
-
setModel in
Configuration data source, needLayout
-
layoutSubview中
Process layout
3.2 For viewController
-
init, only need to pass parameters when we come to need
Do not appear self.view, only common property assignment (such as model, details page url, etc.)
-
In viewDidLoad
Assembled subview
-
viewWilAppear in
Processing of data related to the processing system-level tasks (such as statusbar, network monitoring, etc.)
-
viewDidLayoutSubviews中
Process layout
-
subview initialization in the getter
-
Slimming
ViewModel、RAC、category
4 common class hierarchy
5 Common practice
The loadingView other common unified operation, wrote a UIViewController's classification.
Reproduced in: https: //juejin.im/post/5d077fa0e51d45105d63a50a