我在自定义UIView,anim1和anim2中有两个动画。 Anim1将其委托设置为self,并且在我的类中有一个animationDidStop方法,它触发Anim2。如果我想在Anim2完成时发生其他事情,我该怎么做?我可以使用其他名称指定委托方法吗?
更新
我将两个动画声明为iVars:
CABasicAnimation *topFlip;
CABasicAnimation *bottomFlip;
我构建每个动画并将delgate设置为self eg。
- (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;
}
然后我尝试在animationdidStop中找到bottomFlip:
- (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 iVar
答案 0 :(得分:1)
这似乎有效:
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
//NSLog(@"First Animation stopped");
if (anim ==[topHalfCharLayerFront animationForKey:@"topCharAnim"]) {
NSLog(@"Top Animation is: %@", anim);
topHalfCharLayerFront.hidden = YES;
[bottomHalfCharLayerFront addAnimation:[self bottomCharFlap:bottomHalfCharLayerFront] forKey:@"bottomCharAnim"];
bottomHalfCharLayerFront.hidden = NO;
}
else if ((anim ==[bottomHalfCharLayerFront animationForKey:@"bottomCharAnim"])) {
NSLog(@"Bottom Animation is: %@", anim);
}
答案 1 :(得分:0)
保持对动画的引用为ivars,并将其内存地址与传递给animationDidStop的地址进行比较:
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
{
if (theAnimation == anim1)
{
// Spin off anim2
}
else
{
// anim2 stopped. Make something else occur
}
}