The UIView class defines a rectangular
area on the screen and the interfaces
for managing the content in that area.
At runtime, a view object handles the
rendering of any content in its area
and also handles any interactions with
that content. The UIView class itself
provides basic behavior for filling
its rectangular area with a background
color. More sophisticated content can
be presented by subclassing UIView and
implementing the necessary drawing and
event-handling code yourself. The
UIKit framework also includes a set of
standard subclasses you can use, which
range from simple buttons to complex
tables. For example, a UILabel object
draws a text string and a UIImageView
object draws an image.
Because your application interacts
with the user primarily through view
objects, those objects have a number
of responsibilities. Here are just a
few:
Drawing and animation A view draws
content in its rectangular area using
technologies such as UIKit, Core
Graphics, and OpenGL ES. Some view
properties can be animated to new
values. Layout and subview management
A view may contain zero or more
subviews. Each view defines its own
default resizing behavior in relation
to its parent view. A view can
manually change the size and position
of its subviews as needed. Event
handling A view is a responder and can
handle touch events and other events
defined by the UIResponder class. A
view can use the addGestureRecognizer:
method to install gesture recognizers
to handle common gestures.
The UIViewController class provides
the fundamental view-management model
for iPhone applications. The basic
view controller class supports the
presentation of an associated view,
support for managing modal views, and
support for rotating views in response
to device orientation changes.
Subclasses such as
UINavigationController and
UITabBarController provide additional
behavior for managing complex
hierarchies of view controllers and
views.
You use each instance of
UIViewController to manage a view
hierarchy. A typical view hierarchy
consists of a root view—a reference to
which is available in the view
property of this class—and usually one
or more subviews presenting the actual
content. On iPhone and iPod touch, the
root view typically fills the entire
screen but on iPad this view may fill
only part of the screen. In both
cases, the view controller is
responsible for managing the entire
view hierarchy, including all
subviews.
View controllers are tightly bound to
the views they manage and take part in
the responder chain used to handle
events. View controllers are
themselves descendants of the
UIResponder class and are inserted
into the responder chain between the
managed root view and its superview,
which typically belongs to a different
view controller. If the view
controller’s view does not handle an
event, the view controller itself has
the option of handling the event
before passing the event along to the
superview.
The UIViewController class works with
the application’s window to handle
device orientation changes. If the
view controller supports the new
orientation (as determined by the
return value of its
shouldAutorotateToInterfaceOrientation:
method), it animates the transition
from the current orientation to the
new one. As part of this change, it
also applies any resizing rules in
effect for the views in its view
hierarchy. If you want to make changes
to your view hierarchy as part of the
orientation change, you can override
methods of UIViewController to
implement your changes. For
information on the methods you need to
override, see “Handling View
Rotations.”
View controllers are fundamental to
the design of most iPhone
applications. The sections that follow
provide basic information about using
the methods and properties of the
UIViewController class. For additional
information about using view
controllers to build and manage your
application’s user interface, see View
Controller Programming Guide for iOS.