开发者

Animating a custom property in a CALayer

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

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 updat开发者_开发问答ed 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 doesn't have the same automatic KVC registration support that MonoMac has yet, so you should use:

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


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.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜