15

我正在按照页面底部的示例调用animationDidStop函数。

http://www.informit.com/articles/article.aspx?p=1168314&seqNum=2

作者说:

我有一个专门设计为动画委托的对象,它所做的只是持有对目标对象的引用,接受 animationDidStop: 消息然后释放自己。

这表明您不应该这样做:

[animation setDelegate:self];

我对应用程序编程很陌生,有人可以概述我如何做到这一点吗?或者给我一个解释它的链接。

4

3 回答 3

38

实施:

- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag

在您的委托对象上。您还可以实现:

- (void)animationDidStart:(CAAnimation *)theAnimation

在动画开始时接听电话。

有关更多信息,请参阅代表部分:http: //developer.apple.com/iphone/library/documentation/GraphicsImaging/Reference/CAAnimation_class/Introduction/Introduction.html

于 2010-07-27T22:52:23.320 回答
4

有时需要在动画完成时将图层的实际值设置为 toValue。当它是更复杂的动画时,例如为 CAGradientLayer 的颜色设置动画,这是必需的。

- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
{
  self.gradientLayer.colors = (NSArray *)((CABasicAnimation*)theAnimation).toValue;
}
于 2013-07-02T00:14:43.820 回答
0

只是设置

[UIView setAnimationDelegate:self];

动画开始或结束时不会调用任何 Animation 委托方法。

此问题可以通过以下解决方法之一解决。

1)在您的实施部分添加

@implementation MyViewWithAnimations <UIApplicationDelegate>


2)在你的动画开始提交块添加

[UIView setAnimationWillStartSelector:@selector(animationDidStart:)];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:)];


3) 遵照 Apple 的建议,改用基于块的动画方法。

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIView_Class/UIView/UIView.html

于 2012-08-08T14:53:27.270 回答