Implementing a CAKeyFrameAnimation callback in MonoTouch at the end of an animation set?

邮差的信 提交于 2019-12-23 03:39:13

问题


My code works and I animate, but I'm not sure how to do this:

Animation End Callback for CALayer?

...in MonoTouch.

Here's what i've got:

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 is already inheriting from UIView and I can't inherit from two classes. How would I call a function called "AnimationsComplete()" when this is done animating?


回答1:


I'm not in front of my dev machine, but I think you create a class descending from CAAnimationDelegate, implement the "void AnimationStopped(CAAnimation anim, bool finished) method" and then assign an instance of this class to pathAnimation.Delegate (in your sample).

So, something like this (warning - untested code):

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


来源:https://stackoverflow.com/questions/2219965/implementing-a-cakeyframeanimation-callback-in-monotouch-at-the-end-of-an-animat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!