Graphics Reference
In-Depth Information
LISTING 4-4
Set Up the Animation and Create Timers to Monitor Animation Progress
- (
IBAction
)startAnimation:(
id
)sender;
{
if
( starPath )
{
// Reset our starPath CGMutablePathRef if
// it has already run before
CFRelease
(starPath);
[
self
createPath];
[[[window
contentView
]
layer
]
setNeedsDisplay
];
}
// Define a path for the star shape.
CGMutablePathRef
path =
CGPathCreateMutable
();
CGPathMoveToPoint
(path,
NULL
,240.0, 280.0);
CGPathAddLineToPoint
(path,
NULL
, 181.0, 99.0);
CGPathAddLineToPoint
(path,
NULL
, 335.0, 210.0);
CGPathAddLineToPoint
(path,
NULL
, 144.0, 210.0);
CGPathAddLineToPoint
(path,
NULL
, 298.0, 99.0);
CGPathCloseSubpath
(path);
CAKeyframeAnimation
*animation =
[
CAKeyframeAnimation
animationWithKeyPath
:
@”position”
];
[animation
setDuration
:10.0f];
[animation
setDelegate
:
self
];
// Set the animation's path
[animation
setPath
:path];
// Release the path
CFRelease
(path);
[dotLayer
addAnimation
:animation
forKey
:
@”position”
];
[
NSTimer scheduledTimerWithTimeInterval
:2.0
target
:
self
selector
:
@selector
(legOne:)
userInfo
:
nil
repeats
:
NO
];
[
NSTimer scheduledTimerWithTimeInterval
:4.0