The view hierarchy is used to illustrate the relationship between the view in window.
View hierarchy can be thought of as a flipped tree structure, while window is the topmost node (root node) of the tree. Below the tree is the relationship between father and son view. Visually, the view hierarchy is a closed structure, that is, a view contains one or more view, and the window contains all the view.
View hierarchy is also an important part of responder chain, and when we need to render the contents of a window, the framework of the application uses it to detect the layers of views, to determine the parts that need to be rendered, so as to avoid doing some useless work, This is crucial.
Next look at the definition relationship of the three properties of view in view hierarchy
Parent view of 1.superview,view
Child view of 2.subviews,view
3.window, window with view
There is a difference between iOS and Mac about the third window property.
In iOS, window is a view, but not in a Mac.
In Mac, window has a separate contentview, and all sub-views are included in the Contentview.
In iOS, window plays its own role as a contentview, so the child views are all included in the window.
Such as
At the time of development, sometimes you will encounter
1.ios attempt to present whose view isn't in the window hierarchy
2.warning:attempt to present on whose view isn't in the window hierarchy!
such as such a hint, as long as the inside hint window hierarchy, are the view hierarchy understanding is not in place caused.
The above problems are in a controller's view has not been added to the window time and take present another controller, which is equivalent to the building, 2 floor has not finished, directly to cover the 3 floor, so certainly not.
The most straightforward solution to the problem above is to call present in the controller's viewdidappear. This ensures that the hierarchical structure of the view hierarchy is not chaotic.
View Hierarchy IOS