J'utilise un CAKeyframeAnimation pour animer une vue le long d'un CGPath. Lorsque l'animation est terminée, j'aimerais pouvoir appeler une autre méthode pour effectuer une autre action. Y at-il un bon moyen de le faire?Comment spécifier le sélecteur lorsque CAKeyframeAnimation est terminé?
J'ai regardé en utilisant setAnimationDidStopSelector de UIView: cependant, à partir des docs, cela semble ne s'appliquer que lorsqu'il est utilisé dans un bloc d'animation UIView (beginAnimations et commitAnimations). Je l'ai aussi essayé au cas où, mais cela ne semble pas fonctionner.
Voici quelques exemples de code (ce qui est dans une méthode de sous-classe UIView personnalisée):
// These have no effect since they're not in a UIView Animation Block
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
// Set up path movement
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"path"];
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
pathAnimation.duration = 1.0f;
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, self.center.x, self.center.y);
// add all points to the path
for (NSValue* value in myPoints) {
CGPoint nextPoint = [value CGPointValue];
CGPathAddLineToPoint(path, NULL, nextPoint.x, nextPoint.y);
}
pathAnimation.path = path;
CGPathRelease(path);
[self.layer addAnimation:pathAnimation forKey:@"pathAnimation"];
Une solution que je considérais cela devrait fonctionner, mais ne semble pas être la meilleure façon, est d'utiliser PerformSelector de NSObject: withObject: afterDelay :. Tant que je mets le retard égal à la durée de l'animation, alors ça devrait aller.
Y a-t-il un meilleur moyen? Merci!
Doux, merci! Je dois avoir raté cela en regardant par-dessus les docs. – Daren