我特林当动画的启动和停止,所以我的代码是得到通知:为什么animationDidStart:不起作用?
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:)];
[UIView setAnimationWillStartSelector:@selector(animationDidStart:)];
我实现这些2种方法,但animationDidStop:finished:
得到了通知,并且animationDidStart:
没有。
这里是我的实现:
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
}
- (void)animationDidStart:(CAAnimation *)anim
{
}
当我试图直接调用animationDidStart:
或animationDidStop:finished:
,我的应用程序崩溃,并报道说,选择找不到。但根据CAAnimation.h中的以下几行,如果我导入QuatzCore框架,NSObject的所有实例都应该响应这两种方法。我的理解是否正确?
/* 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
我有点困惑。我认为CAAnimationDelegate类别与NSObject记录在: http://developer.apple.com/iphone/library/documentation/GraphicsImaging/Reference/CAAnimation_class/Introduction/Introduction.html#//apple_ref/occ/instm/NSObject/ animationDidStart: – 2010-07-28 16:51:27
关于术语的一个词:'CAAnimation'不是一个“类别”,而是“NSObject”的“继承”,它只是说实际上是一个对象。 'CAAnimationDelegate'是一个协议,它是一组规则,告诉你应该/可能提供哪些方法来建立一些交互。 – mvds 2010-07-28 17:36:41
@MQ顾:你是对的,我没有足够的时间进行研究,对不起!但它不会改变你的问题。 CAAnimation是一个抽象类,由UIView使用(实现)来执行他基本的动画。你需要使用UIView定义的选择器来使你的代码工作。 – thatsdisgusting 2010-07-28 22:00:04