在CALayer中对自定义属性进行动画处理 [英] Animating a custom property in a CALayer

查看:58
本文介绍了在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.

这篇关于在CALayer中对自定义属性进行动画处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆