Skip to Content
Beginning iOS 5 Application Development
book

Beginning iOS 5 Application Development

by Wei-Meng Lee
January 2012
Beginner content levelBeginner
655 pages
16h 35m
English
Wrox
Content preview from Beginning iOS 5 Application Development

USING THE NSTIMER CLASS

One of the easiest ways to get started with animation is to use the NSTimer class. The NSTimer class creates timer objects, which enable you to call a method at a regular time interval. Using an NSTimer object, you can update the position of an image at regular time intervals, thereby creating the impression that it is being animated.

In the following Try It Out, you learn how to display a bouncing ball on the screen using the NSTimer class. When the ball touches the sides of the screen, it bounces off in the opposite direction. You also learn how to control the frequency with which the ball animates. Download the code files indicated for this and other Try It Out features within this chapter.

TRY IT OUT: Animating a Ball

image

  1. Using Xcode, create a new Single View Application (iPhone) project and name it Animation. You will also use the project name as the Class Prefix and ensure that you have the Use Automatic Reference Counting option unchecked.
  2. Drag and drop an image named tennisball.jpg to the Supporting Files folder in Xcode. When the Add dialog appears, check the Copy Item into the Destination Group's Folder (If Needed) option so that the image is copied into the project (see Figure 13-1).

    image

    FIGURE 13-1

  3. Select the AnimationViewController.xib file to edit ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering iOS 12 Programming - Third Edition

Mastering iOS 12 Programming - Third Edition

Donny Wals
What Successful Project Managers Do

What Successful Project Managers Do

W. Scott Cameron, Jeffrey S. Russell, Edward J. Hoffman, Alexander Laufer

Publisher Resources

ISBN: 9781118144251Purchase book