在 CALayer 中对自定义属性进行动画处理
我正在尝试让动画在 CALayer 中的自定义属性上工作。
但我就是不知道如何让它正常工作。密钥“myCounter”永远不会发送到 NeedsDisplayForKey。我缺少一些步骤吗?下面是我正在测试的类,我将其添加到其他地方的图层中。有没有人有自定义属性来使用单点触控制作动画?
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;
}
}
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 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;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
MonoTouch 不具备与 MonoMac 相同的自动 KVC 注册支持,因此您应该使用:
MonoTouch doesn't have the same automatic KVC registration support that MonoMac has yet, so you should use:
不幸的是,这对于 MonoTouch 来说是不可能做到的 - 但我们已经在下一个测试版 (5.3.3) 中修复了它,希望很快就会发布。
5.3.3 发布后,您可以使用此示例:https:// github.com/xamarin/monotouch-samples/tree/monotouch-5.4/CustomPropertyAnimation 了解如何操作。
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.