CAAnimation确定哪个动画是哪个

时间:2012-10-05 20:38:38

标签: iphone objective-c ios ipad caanimation

我有三个CAShapeLayer,每个都有不同的路径,但是这三个层应用了相同的动画,即:

 [self animateToLineLayer:self.leftDottedLine_ withKey:@"leftLineAnimated"];

   - (void) animateToLineLayer:(CAShapeLayer *) line withKey:(NSString *) key
    {
        CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
        [pathAnimation setFromValue:[NSNumber numberWithFloat:0.0f]];
        [pathAnimation setToValue:[NSNumber numberWithFloat:1.0f]];
        [pathAnimation setDuration:10.0];
        [pathAnimation setDelegate:self];
        [pathAnimation setFillMode:kCAFillModeForwards];
        [line addAnimation:pathAnimation forKey:key];
    }

    then I try to find this animation back by doing:

    - (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)flag
    {
        if (animation == [self.leftDottedLine_ animationForKey:@"strokeEnd"]) {
            NSLog(@"DONE");
        }

        if (![self.leftDottedLine_ isNotNull]){
            NSLog(@"NIL");
        }

        NSLog(@"JUST DONE");
    }

但问题是它永远不会打印完成!这是为什么?

1 个答案:

答案 0 :(得分:0)

您可能需要查看有关如何在animationDidStop委托中识别动画的提示: How to identify CAAnimation within the animationDidStop delegate?

您确定将自己设为代表吗?此外,也许==不起作用。尝试isEqualTo:或上面链接中所述的字符串比较。