开发者

Why does animationDidStart: not work?

I'm tring to get notified when animation starts and stops, so my code is:

[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:)];
[UIView setAnimationWillStartSelector:@selector(animatio开发者_开发技巧nDidStart:)];

I do implement these 2 methods, but animationDidStop:finished: got notified, and animationDidStart: did not.

Here's my implementation:

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
}

- (void)animationDidStart:(CAAnimation *)anim
{
}

When I tried to call animationDidStart: or animationDidStop:finished: directly, my app crashed and reported that the selector could not be found. But according to following lines in CAAnimation.h, if I import QuatzCore framework, all the instances of NSObject should response to these 2 methods. Is my understanding correct?

/* 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


Reading The Fine Manual, I see

The selector should have the same arguments as the beginAnimations:context: method,
an optional application-supplied identifier and context. Both of these arguments can
be nil.

So I presume you could at least make the selector eat the right arguments.

It seems you are implementing a different protocol, have a look at the UIView docs.


According to the UIView documentation the setAnimationWillStartSelector: message expects a selector with a signature like the + (void)beginAnimations:(NSString *)animationID context:(void *)context. The selector you provide has a wrong signature and will therefor not be called. The CAAnimationDelegate category to NSObject is not even documented, so you probably need to know exactly what you are doing. However your problem is the wrong selector signature.


In your UIView animation block, setting the selectors should look like this:

[UIView setAnimationWillStartSelector:@selector(animationWillStart:context:)];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜