Graphics Reference
In-Depth Information
discussed in greater detail in the next section. What we have seen in this demonstration
is that we can smoothly move elements around the screen by utilizing Core Animation
and creating some impressive effects with only a few lines of code.
The techniques in this section, along with high quality graphics, can be used to create
dazzling custom user interface elements that behave in any manner you choose.
Doing Animations at the UIView Level
In addition to manipulating the Core Animation layers directly, we can also apply a less
aggressive design to our animations. There are numerous situations in which we want to
provide some animation in a user inter-
face, but it is overkill to build up a
CABasicAnimation just to provide a
simple animation.
Fortunately, there is another way to do
just that. The desktop has a way to
perform simple implicit animations by
calling -animator on any object that can
handle it. On Cocoa Touch it is a bit
different and is handled by class
methods on the UIView class.
In this example, we build a Cocoa Touch
application that presents the user with
an image and a button. When the
button is pressed, the image bounces
three times on the screen. While the
image is bouncing, the button hides.
You can download the example project
and run it in the simulator. The final
application is shown in Figure 13-8.
FIGURE 13-8
The Completed Application
Building the Application
For this example, we start with the view-based template from Xcode. From the template,
open the main view controller and add two items. This example uses an image from the
Xcode Tools examples, along with a UIButton that was added to the view. The result is
shown in Figure 13-9.
Building the View Controller
The next step in the application is to add the logic to the view controller. In the sample
application included with this chapter, the view controller we are editing is named
MainViewController.m . Depending on the version of Xcode you run, the generated name
from the template might be different.
 
Search WWH ::




Custom Search