Je Tring pour être averti lorsque l'animation démarre et arrête, donc mon code est:Pourquoi animationDidStart: ne fonctionne pas?
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:)];
[UIView setAnimationWillStartSelector:@selector(animationDidStart:)];
je mettre en œuvre ces 2 méthodes, mais animationDidStop:finished:
mais j'ai notifié, et ne l'ont pas animationDidStart:
.
Voici mon implémentation:
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
}
- (void)animationDidStart:(CAAnimation *)anim
{
}
Quand j'ai essayé d'appeler directement animationDidStart:
ou animationDidStop:finished:
, mon application tombé en panne et a signalé que le sélecteur n'a pas été trouvé. Mais selon les lignes suivantes dans CAAnimation.h, si j'importe le framework QuatzCore, toutes les instances de NSObject devraient répondre à ces 2 méthodes. Est-ce que ma compréhension est correcte?
/* Delegate methods for CAAnimation. */
@interface NSObject (CAAnimationDelegate)
/* Called when the animation begins its active duration. */
- (void)animationDidStart:(CAAnimation *)anim;
/* Called when the animation either completes its active duration or
* is removed from the object it is attached to (i.e. the layer). 'flag'
* is true if the animation reached the end of its active duration
* without being removed. */
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag;
@end
Je suis un peu confus. Je pense que la catégorie CAAnimationDelegate à NSObject est documentée dans: http://developer.apple.com/iphone/library/documentation/GraphicsImaging/Reference/CAAnimation_class/Introduction/Introduction.html#//apple_ref/occ/instm/NSObject/ animationDidStart: –
un mot sur la terminologie: 'CAAnimation' n'est pas une" catégorie ", mais" hérite "de' NSObject', qui ne dit rien de plus que c'est en fait un objet. 'CAAnimationDelegate' est un protocole, qui est un ensemble de règles indiquant les méthodes que vous devez/pouvez utiliser pour établir une interaction. – mvds
@MQ Gu: Vous avez raison, je n'ai pas pris assez de temps pour la recherche, désolé! Mais cela ne change rien à votre problème. CAAnimation est une classe abstraite, utilisée (implémentée) par UIView pour effectuer les animations de base. Vous devez utiliser le sélecteur défini par UIView pour que votre code fonctionne. – thatsdisgusting