2011-06-22 105 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

我知道,這是爲了其他人會遇到這個,因爲我知道這是一個艱難的方式,並沒有看到它在互聯網上的任何地方提到:( –