2015-04-04 96 views
0

我遇到與iOS CABasicAnimation有關的問題。無論我做什麼,我都無法啓動方法animationDidStart:animationDidStop:finished:。提前未調用的CAAnimation委託方法

- (void)start{ 
    [self removeAllAnimations]; 

    CABasicAnimation *pathAnimation = [self makeAnimationForKey:@"strokeEnd"]; 
    [self addAnimation:pathAnimation forKey:@"strokeEnd"]; 
} 

- (CABasicAnimation *)makeAnimationForKey:(NSString *)key { 
    CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:key]; 
    anim.fromValue = [NSNumber numberWithFloat:0.f]; 
    anim.toValue = [NSNumber numberWithFloat:1.f]; 

    anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; 
    anim.duration = self.duration; 
    anim.delegate = self; 
    return anim; 
} 

- (void)animationDidStart:(CAAnimation *)anim{ 
    NSLog(@"HERE START"); 
} 

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{ 
    NSLog(@"HERE STOP"); 
} 

任何提示或幫助將不勝感激,謝謝:我的類繼承CAShapeLayer並執行它裏面的動畫!

+1

記住層被克隆的動畫時,那麼你可能不會得到你想要使用像這樣的一個子類的效果。 – 2015-04-04 05:24:02

+0

感謝提醒大衛,我一定會記住它。 – 2015-04-05 19:17:02

+2

__請注意''CAAnimation''''delegate'是強大的,所以你可能需要將它設置爲'nil'來避免保留週期!__ – 2016-08-10 12:35:37

回答

1

好吧,所以它變成我的子類我有一個屬性稱爲持續時間。儘管它沒有被記錄爲CALayer的區別,但持續時間是其協議之一CAMediaTiming的一部分。該方法從未被解僱,因爲該屬性被我的子類覆蓋。

+0

這被視爲記錄在案。您通常不會提到在對象符合的協議中聲明的屬性或方法。 – 2015-04-06 09:51:13

6

你必須向層分配動畫之前設置委託:

popIn.delegate = self; 
[annotation.layer addAnimation:popIn forKey:@"popIn"];