Graphics Reference
In-Depth Information
LISTING 13-3
Continued
CAKeyframeAnimation *animation = nil ;
animation = [CAKeyframeAnimation animationWithKeyPath: @”position” ];
[animation setDuration:10.0f];
[animation setDelegate: self ];
[animation setPath:starPath];
CFRelease(starPath), starPath = nil ;
[[textLabel layer] addAnimation:animation forKey: @”position” ];
}
When implemented, this method makes the UILabel move in a star pattern, following
the CGPath we defined. When the path has finished CAKeyframeAnimation notifies the
application delegate (because it is also the animation's delegate) via the method in
Listing 13-4.
LISTING 13-4
CAAnimation Delegate Method
- ( void )animationDidStop:(CAAnimation *)theAnimation finished:( BOOL )flag
{
[drawButton setEnabled: YES ];
}
Adding the animationDidStop: method completes our work on the Star application.
Running the application produces a black window with the button and label. Pressing the
button causes the label to trace a star-shaped pattern on the screen. When the animation
receives the callback, the button is reenabled so that the animation can be fired again.
Core Animation and Cocoa Touch Example
Another example of working with Core Animation on Cocoa Touch is integrating with
the touch system. Unlike a key press or mouse event on a desktop computer, the touch
system is designed for taps, drags, and multitouch events. This example focuses on
touches and drags.
All UIView objects are capable of receiving touch events, but they are turned off by
default. To enable touch events, call the -setUserInteractionEnabled: method on the
UIView and pass the Boolean value of YES . After you do that, you begin receiving touch
events that occur within the bounds of the view. There are four possible events that we
can receive:
.
touchesBegan
.
touchesEnded
.
touchesMoved
.
touchesCancelled
 
 
Search WWH ::




Custom Search