2011-06-22 55 views
3

我正在制作一个CABasicAnimation,问题是animationDidStop委托方法没有被调用。我不知道为什么,但希望有人知道。CABasicAnimation - animationDidStop不叫

这里是我的动画:

CABasicAnimation *theAnimation; 
theAnimation = [CABasicAnimation animationWithKeyPath: @"transform.translation.x"]; 
theAnimation.duration = 54; 
//theAnimation.repeatCount = 6; 
theAnimation.autoreverses = YES; 
theAnimation.removedOnCompletion = YES; 

theAnimation.fromValue = [NSNumber numberWithFloat: (self.myImageView.frame.size.height/5) + (self.view.frame.size.height - self.myImageView.center.x)]; 
theAnimation.toValue = [NSNumber numberWithFloat: 6.0 - (self.myImageView.frame.origin.y + self.myImageView.frame.size.height)]; 

//[self.myImageView.layer addAnimation:theAnimation forKey: @"animateLayer"]; 
[theAnimation setValue:@"Animation1" forKey:@"animateLayer"]; 
[[self.myImageView layer] addAnimation:theAnimation forKey:nil]; 

而且,这里是我的animationDidStop方法:

- (void)animationDidStop:(CABasicAnimation *)theAnimation finished:(BOOL)flag { 

    NSString* value = [theAnimation valueForKey:@"animateLayer"]; 
    if ([value isEqualToString:@"Animation1"]) 
    { 
     [self themethod]; 
     return; 
    } 


    if ([value isEqualToString:@"Animation2"]) 
    { 
     [self themethod]; 
     return; 
    } 
} 

有谁知道为什么发生这种情况?

回答

9

您需要设置代表才能拨打animationDidStop

theAnimation.delegate = class (self) 
+0

__Be知道'CAAnimation'的'delegate'强,所以你可能需要将其设置为'nil'避免保留周期!__ –

+0

谢谢,但在2011年“强”可能尚未实现... :) – elp

+0

我知道,这是为了其他人会遇到这个,因为我知道这是一个艰难的方式,并没有看到它在互联网上的任何地方提到:( –