2009-04-03 21 views

Respuesta

4

Puede que esta no sea la mejor solución, pero funcionó para mí. Le dije a la animación que se revirtiera automáticamente, y luego comencé a medio camino. Pero para evitar que volviera a animar, necesitaba terminarla antes.

- (void) animate { 
    CAKeyframeAnimation * pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; 
    pathAnimation.path = path; 
    pathAnimation.duration = 15.0; 
    pathAnimation.calculationMode = kCAAnimationPaced; 
    pathAnimation.timeOffset = pathAnimation.duration; 
    pathAnimation.autoreverses = YES; 

    NSString * key = @"pathAnimation"; 
    [animatedView.layer addAnimation:pathAnimation forKey:key]; 
    [NSTimer scheduledTimerWithTimeInterval:pathAnimation.duration target:self selector:@selector(endAnimation:) userInfo:key repeats:NO]; 
} 

- (void) endAnimation:(NSTimer *)timer { 
    [animatedView.layer removeAnimationForKey:timer.userInfo]; 
} 

Si existe una manera mejor, me gustaría saber.

28
animation.speed = -1; 

?

+0

Sí. Eso es definitivamente mejor. Ojalá hubiera pensado en eso antes. –

+0

¡Definitivamente grandes gracias! – BoilingLime

+0

¿Dónde lo aprendiste? No puedo encontrar en Apple Docs esta característica. – surfrider

Cuestiones relacionadas