2010-02-08 53 views
1

我的代码工作,我的动画,但我不知道如何做到这一点:在动画集结束时在MonoTouch中实现CAKeyFrameAnimation回调?

Animation End Callback for CALayer?

...在MonoTouch的。

这里就是我已经有了:

public partial class MyCustomView: UIView 
{ 
    // Code Code Code 

    private void RunAnimation() 
    {   
     CAKeyFrameAnimation pathAnimation = new CAKeyFrameAnimation(); 
     pathAnimation.KeyPath = "position"; 
     pathAnimation.Path = trail; //A collection of PointFs 
     pathAnimation.Duration = playbackSpeed; 
     Character.Layer.AddAnimation(pathAnimation,"MoveCharacter"); 
    } 

    //Code Code Code 
} 

MyCustomView已经从UIView的继承和我无法从两个类继承。当完成动画时,如何调用名为“AnimationsComplete()”的函数?

回答

4

我不是在我的开发机器前,但我认为你创建一个从CAAnimationDelegate降序的类,实现“void AnimationStopped(CAAnimation anim,bool finished)方法”,然后将该类的一个实例分配给pathAnimation .Delegate(在你的示例中)。

所以,这样的事情(警告 - 未经测试的代码):

public partial class MyCustomView: UIView 
{ 
    private void RunAnimation() 
    {   
     CAKeyFrameAnimation pathAnimation = new CAKeyFrameAnimation(); 

     // More code. 

     pathAnimation.Delegate = new MyCustomViewDelegate(); 

    } 
} 

public class MyCustomViewDelegate : CAAnimationDelegate 
{ 
    public void AnimationStopped(CAAnimation anim, bool finished) 
    { 
     // More code. 
    } 
} 
+0

好吧,这是我不能正确解释这个故障。问题是我使用的类已经从UIView继承,所以我不能从两个类继承。我会更新我的问题。 – Abel 2010-02-08 16:25:47

+1

我认为这不重要。 CAAnimationDelegate将是一个*独立的*类。所以,你将拥有MyCustomView和MyCustomViewDelegate类。然后,在RunAnimation()中,您将拥有pathAnimation.Delegate = new MyCustomViewDelegate(); (例如)。 – dommer 2010-02-08 18:37:51

+0

你完全正确。谢谢您的帮助! – Abel 2010-02-09 04:22:54