View hierarchy is also an important part of the responder chain. When we need to render the content in the window, the framework of the application will use it to detect the layer level of views and determine the part to be rendered, so as to avoid doing some useless work. This is very important.
Next, let’s look at the definition relationship of the three attributes of view in view hierarchy
1. Supervisor, parent view of view
2. Subviews, subviews of view
3. Window, including the window of view
The third window property is different between IOS and MAC.
In IOS, window is a view, but not in MAC.
In MAC, window has a single contentview, and all subviews are included in the contentview.
In IOS, window itself plays the role of content view, so all sub views are included in window.
In the process of development, there are some problems
1.ios attempt to present whose view is not in the window hierarchy
2.Warning: Attempt to present on whose view is not in the window hierarchy!
And so on. As long as there is a window hierarchy in it, it is caused by the poor understanding of viewhierarchy.
The above problem is that when the view of a controller is not added to the window, another controller is called present. This is equivalent to building a building. If the second floor is not finished, you can go to build the third floor directly. This is definitely not good.
the most direct solution to the above problem is to call present in the controller’s viewdidappearance. This ensures that the hierarchy of view hierarchy is not disordered.