2012-07-03 3 views
3

Je sais que cette question est souvent posée mais j'ai essayé toutes les autres réponses et je n'arrive pas à comprendre pourquoi le sélecteur d'arrêt d'animation n'est pas appelé. Voici le code:setAnimationDidStopSelector: ne pas se faire appeler

-(void) moveImage:(UIImageView *)image duration:(NSTimeInterval)duration curve:(int)curve x:(CGFloat)x y:(CGFloat)y annKey:(NSString *) annKey{ 

[UIView setAnimationDelegate:self]; 
[UIView setAnimationDuration:duration]; 
[UIView setAnimationCurve:curve]; 
[UIView setAnimationBeginsFromCurrentState:YES]; 
[UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)]; 
CGAffineTransform transform = CGAffineTransformMakeTranslation(x, y); 
image.transform = transform; 
[UIView beginAnimations:annKey context:NULL]; 
[UIView commitAnimations]; 

}

Ceci est la fonction principale d'animation qui est envoyé tous les paramètres corrects.

- (void)animationFinished:(NSString *)animationID finished:(BOOL)finished context:(void *)context 
{ 
if ([animationID isEqualToString:@"Burn"]) 
{ 
    NSLog(@"Animation: %@ has finished.",animationID); 
} 

NSLog(@"This does not get called, why not?"); 
} 

Aucun de mes NSLogs n'affiche le texte. Qu'est-ce que je fais mal?

+0

Pourquoi avez-vous deux 'beginAnimations'? – RyJ

+0

Désolé, c'était une erreur, j'ai enlevé le premier du code. Mais le problème existe toujours. – JH95

+0

Déplacez cette ligne, '[UIView beginAnimations: annKey context: NULL];' en haut de la méthode 'moveImage: duration: courbe: x: y: annKey:'. – titaniumdecoy

Répondre

8

Vous devez faire tho -

[UIView beginAnimations:annKey context:NULL]; 
[UIView setAnimationDelegate:self]; 
[UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)]; 

// Now define rest. 
[UIView setAnimationDuration:duration]; 
[UIView setAnimationCurve:curve]; 
[UIView setAnimationBeginsFromCurrentState:YES]; 
CGAffineTransform transform = CGAffineTransformMakeTranslation(x, y); 
image.transform = transform; 

[UIView commitAnimations]; 
+0

Merci! Fonctionne maintenant! – JH95

3

Je ne sais pas quel est le problème, mais vous devriez vraiment pas utiliser beginAnimations/commitAnimations. Au lieu de cela, utilisez des animations de bloc. Vous définissez le code d'achèvement directement dans la partie d'achèvement de l'appel.

[UIView animateWithDuration:2.0 
         delay:0.0 
        options:UIViewAnimationOptionCurveEaseOut 
       animations:^{ 
        // animation code 
       } 
       completion:^(BOOL finished){ 
        // completion code 
       }]; 
Questions connexes