Chapter 4. The View

This chapter explains the main concepts behind views. You will learn about view geometry in Section 4.1. In Section 4.2, we cover the topic of view hierarchy. Next, Section 4.3 discusses, in great detail, the multitouch interface. In this section, you will learn how to recognize multitouch gestures. After that, we discuss several animation techniques in Section 4.4. Finally, Section 4.5 deals with how to use Quartz 2D functions for drawing inside a view.

View Geometry

There are three geometric properties of the UIView class that you need to understand. These properties are: frame, bounds, and center. Before explaining these properties, let's first look at some of the structures and functions used in specifying the values for these properties.

Useful geometric type definitions

The following types are used throughout the text:

  • CGFloat represents a floating number and is defined as:

    typedef float CGFloat;
  • CGPoint is a structure that represents a geometric point. It is defined as:

    struct CGPoint {
       CGFloat x;
       CGFloat y;
    typedef struct CGPoint CGPoint;

    The x value represents the x-coordinate of the point and the y value represents its y-coordinate.

    You will use CGPoint a lot. CGPointMake() is a convenient function defined to make a CGPoint from a pair of x and y values, and is defined as follows:

    CGPoint CGPointMake (
       CGFloat x,
       CGFloat y
  • CGSize is a structure used to represent width and height values, and is declared as follows:

    struct CGSize { CGFloat width; CGFloat height; ...

Get iPhone SDK Programming: Developing Mobile Applications for Apple iPhone and iPod touch now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.