在动画集的末尾在MonoTouch中实现CAKeyFrameAnimation回调?

时间:2010-02-08 06:34:35

标签: callback xamarin.ios 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()”的函数?

1 个答案:

答案 0 :(得分:4)

我不在我的开发机器前面,但我认为你创建了一个从CAAnimationDelegate降序的类,实现了“void AnimationStopped(CAAnimation anim,bool finished)方法”,然后将此类的实例分配给pathAnimation。代表(在您的样本中)。

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

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.
    }
}