The View Hierarchy

Every application has a single instance of UIWindow that serves as the container for all the views in the application. UIWindow is a subclass of UIView, so the window is itself a view. The window is created when the application launches. Once the window is created, other views can be added to it.

When a view is added to the window, it is said to be a subview of the window. Views that are subviews of the window can also have subviews, and the result is a hierarchy of view objects with the window at its root (Figure 3.2).

Figure 3.2  An example view hierarchy and the interface that it creates

Diagrammatic representation of View Hierarchy depicts the view objects of Wikipedia website in an iOS screen.

Once the view hierarchy is created, it will be drawn to the screen. This process can be broken into two steps:

  • Each view in the hierarchy, including the window, draws itself. It renders itself to its layer, which you can think of as a bitmap image. (The layer is an instance of CALayer.)

  • The layers of all the views are composited together on the screen.

Figure 3.3 depicts another example view hierarchy and the two drawing steps.

Figure 3.3  Views render themselves and then are composited together

Diagrammatic representation of the View Hierarchy for a Calculator app in iOS.

For WorldTrotter, you are going to create an interface composed of different views. There will be four instances of UILabel and one instance of UITextField that will allow the user to enter a temperature in Fahrenheit. Let’s get started.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset