【问题标题】:Implementing a CAKeyFrameAnimation callback in MonoTouch at the end of an animation set?在动画集结束时在 MonoTouch 中实现 CAKeyFrameAnimation 回调?
【发布时间】:2010-02-08 06:34:34
【问题描述】:

我的代码有效并且我制作了动画,但我不知道该怎么做:

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()”的函数?

【问题讨论】:

    标签: callback xamarin.ios cakeyframeanimation


    【解决方案1】:

    我不在我的开发机器前,但我认为您创建了一个从 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.
        }
    }
    

    【讨论】:

    • 好的,这是我没有正确解释的错。问题是我使用的类已经从 UIView 继承,所以我不能从两个类继承。我会更新我的问题。
    • 我认为这无关紧要。 CAAnimationDelegate 将是一个单独的 类。因此,您将拥有 MyCustomView 和 MyCustomViewDelegate 类。然后,在 RunAnimation() 中,您将拥有 pathAnimation.Delegate = new MyCustomViewDelegate(); (例如)。
    猜你喜欢
    • 1970-01-01
    • 2015-09-29
    • 2010-09-22
    • 1970-01-01
    • 2013-12-15
    • 2017-06-07
    • 1970-01-01
    • 2016-11-19
    相关资源
    最近更新 更多