[英]CAAnimation delegate methods not called
我在iOS CABasicAnimation
上遇到問題。 無論我做什么,我都無法啟動animationDidStart:
和animationDidStop:finished:
方法。 我的課程是CAShapeLayer
子類,並在其中執行動畫:
- (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");
}
任何提示或幫助,將不勝感激,在此先感謝!
您必須在將動畫分配給圖層之前設置委托:
popIn.delegate = self;
[annotation.layer addAnimation:popIn forKey:@"popIn"];
好的,這樣在我的子類中就有了一個名為duration的屬性。 即使未將其記錄為與CALayer
分開,但持續時間仍是其稱為CAMediaTiming
的協議CAMediaTiming
。 這些方法從未被觸發過,因為該屬性已通過我的子類覆蓋。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.