2009-04-03 8 views

risposta

4

Questa potrebbe non essere la soluzione migliore, ma ha funzionato per me. Ho detto all'animazione di eseguire l'autoreverse, quindi l'ho avviato a metà. Ma per impedirgli di tornare ad animare di nuovo, dovevo terminarlo prima.

- (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]; 
} 

Se esiste un modo migliore, mi piacerebbe sapere.

28
animation.speed = -1; 

?

+0

Sì. Questo è decisamente meglio. Vorrei averlo pensato prima. –

+0

Sicuramente grande grazie! – BoilingLime

+0

Dove l'hai imparato? Non riesco a trovare in apple doc questa funzione. – surfrider

Problemi correlati