在CALayer中设置自定义属性的动画

时间:2011-02-12 02:43:39

标签: xamarin.ios calayer

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

但我只是无法弄清楚如何使其正常工作。键“myCounter”永远不会发送到NeedsDisplayForKey。我缺少一些步骤吗?下面是我正在测试的类,我在其他地方添加了一个层。有没有人使用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;

    }
    }

2 个答案:

答案 0 :(得分:0)

MonoTouch没有与MonoMac相同的自动KVC注册支持,因此您应该使用:

public uint myCounter { [Export ("myCounter")] get; [Export ("setMyCounter:")] set; }

答案 1 :(得分:0)

不幸的是,MonoTouch无法做到这一点 - 但我们已经为下一个测试版(5.3.3)做了修复,希望很快就会发布。

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