Quote:
Originally Posted by screwtape
Hi All,
I'm looking at subclassing CAKeyframeAnimation in order to sync an animation with the associated sound effects. I can't see any methods in the documentation which do anything but I presume that the CALayer must call some methods in the CAAnimation to do the work, but it doesn't seem to be documented.
Anyone any ideas how to do this?
Screwtape.
|
If you just need to sync an animation with the associated sound effects you don't need to subclass.
You can just use
Code:
- (void)animationDidStart:(CAAnimation *)anim;
from the
CAAnimation Class
here is the sample from one of my view controllers
Code:
- (void)startAnimation{
NSArray* prisonImages2 = [[NSArray alloc] initWithObjects:
(id)[Utils loadImage:@"ZAM_01.png"].CGImage,
(id)[Utils loadImage:@"ZAM_02.png"].CGImage,
(id)[Utils loadImage:@"ZAM_03.png"].CGImage,
(id)[Utils loadImage:@"ZAM_04.png"].CGImage,
nil];
CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
animation. values = prisonImages2;
[prisonImages2 release];
animation. duration = 2;
animation. autoreverses = NO;
animation.delegate = self;
animation.calculationMode = kCAAnimationDiscrete;
[prisonImageView.layer addAnimation: animation forKey: @"contents" ] ;
}
- (void)animationDidStart:(CAAnimation *)anim{
//play your sound, it will start when the animation begins its active duration
}