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
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 shows another example view hierarchy and the two drawing steps.
Figure 3.3 Views render themselves and then are composited together
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 in a temperature in Fahrenheit. Let’s get started.