1

我的代码有效并且我制作了动画,但我不确定如何执行此操作:

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

1 回答 1

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.
    }
}
于 2010-02-08T08:40:05.877 回答