在CALayer中对自定义属性进行动画处理

在CALayer中对自定义属性进行动画处理

问题描述:

我正在尝试让动画在CALayer中的自定义属性上工作。

I'm trying to get animation working on a custom property in a CALayer.

但是我只是无法弄清楚如何使其正常工作。 。密钥 myCounter永远不会发送到NeedsDisplayForKey。我缺少一些步骤吗?以下是我正在测试的课程,我将该课程添加到其他位置的图层中。有没有人拥有使用单点触控进行动画处理的自定义属性?

But I just just am not able to figure out how to get this working correctly. The key "myCounter" is never sent to NeedsDisplayForKey. Are there some steps I'm missing? Below is the class I'm testing which I add to a layer elsewhere. Has anyone got a custom property to animate using monotouch?

    public class TestProperty : CALayer
    {
    //this line updated based on feedback below**********
        public uint myCounter { [Export ("myCounter")] get; [Export setMyCounter:")]  set; }


    public TestProperty ()
    {
        CABasicAnimation anim = CABasicAnimation.FromKeyPath("myCounter");
        anim.From = NSNumber.FromInt32(1);
        anim.To = NSNumber.FromInt32(10);
        anim.Duration = 1.0f;
        anim.RepeatCount = float.MaxValue;
        anim.AutoReverses = true;
        this.AddAnimation(anim,null);
    }

    [Export ("needsDisplayForKey:")]
    static bool NeedsDisplayForKey (NSString key)
    {
        Console.WriteLine("{0}", key.ToString());

        if(key.Equals("myCounter"))
        {
            return true; //never gets here
        }
        else
            return false;

    }
    }


很遗憾,这无法与MonoTouch一起使用-但是我们已针对下一个测试版(5.3.3)进行了修复,

This has unfortunately been impossible to do with MonoTouch - but we've fixed it for the next beta (5.3.3) which will hopefully be released soon.

5.3.3发布后,您可以使用以下示例: https://github.com/xamarin/monotouch-samples/tree/monotouch-5.4/CustomPropertyAnimation ,了解如何操作。

Once 5.3.3 has been released you can use this sample: https://github.com/xamarin/monotouch-samples/tree/monotouch-5.4/CustomPropertyAnimation to see how to do it.