views:

231

answers:

1

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

http://stackoverflow.com/questions/296967/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?

+3  A: 

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.
    }
}
dommer
Ok, this is my fault for not explaining this correctly. The issue is the class I'm using already inherits from UIView so I can't inherit from two classes. I'll update my question.
Abel Martin
I don't think this will matter. The CAAnimationDelegate will be a *separate* class. So, you'll have MyCustomView and MyCustomViewDelegate classes. Then, in RunAnimation() you'll have pathAnimation.Delegate = new MyCustomViewDelegate(); (for example).
dommer
You're exactly right. Thanks for the help!
Abel Martin