我在自定义UIView,anim1和anim2中有两个动画。 Anim1将它的委托设置为self,并且在我的类中有一个animationDidStop方法触发Anim2。如果我想在Anim2完成时发生其他事情,我该怎么做?我可以使用不同的名称指定委托方法吗?核心动画animationDidStop与链接动画
UPDATE
我声明两个动画作为IVARS:
CABasicAnimation *topFlip;
CABasicAnimation *bottomFlip;
我建立每个动画并设置delgate自例如
- (CABasicAnimation *)bottomCharFlap: (CALayer *)charLayer
{
bottomFlip = [CABasicAnimation animationWithKeyPath:@"transform"];
charLayer.transform = CATransform3DMakeRotation(DegreesToRadians(0), 1, 0, 0); //set to end pos before animation
bottomFlip.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(DegreesToRadians(-360), 1, 0, 0)];
bottomFlip.fromValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(DegreesToRadians(-270), 1, 0, 0)];
bottomFlip.autoreverses = NO;
bottomFlip.duration = 0.5f;
bottomFlip.repeatCount = 1;
bottomFlip.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseOut];
bottomFlip.delegate = self;
bottomFlip.removedOnCompletion = FALSE;
return bottomFlip;
}
然后我试图找到bottomFlip在animationdidStop:
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag {
if (theAnimation == bottomFlip) {
NSLog(@"Bottom Animation is: %@", bottomFlip);
}
NSLog(@"Animation %@ stopped",theAnimation);
[bottomHalfCharLayerFront addAnimation:[self bottomCharFlap:bottomHalfCharLayerFront] forKey:@"bottomCharAnim"];
bottomHalfCharLayerFront.hidden = NO;
topHalfCharLayerFront.hidden = YES;
//insert the next one???
}
“动画停止”记录,但没有别的也就是说,它似乎并没有认识到bottomFlip伊娃
谢谢!这可以通过addAnimation forKey的'forKey'来完成吗?或者,这只适用于删除动画? – codecowboy 2010-08-31 03:23:37
我已经在上面添加了一些代码。如果我在添加动画后记录动画的内存地址,然后将其记录在animationDidStop中,则内存地址不匹配。我认为这就是为什么你的建议没有奏效。如果(theAnimation == anim1)从未成功。 – codecowboy 2010-08-31 06:04:54