使用Monotouch中的CoreAnimation为自定义属性设置动画效果? [英] Animate a custom property using CoreAnimation in Monotouch?

查看:114
本文介绍了使用Monotouch中的CoreAnimation为自定义属性设置动画效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这与此处发布的问题基本相同:动画中的自定义属性一年前一个CALayer
并没有得到回答。

This is essentially the same question as posted here: Animating a custom property in a CALayer over a year ago and hasn't been answered.

我创建一个自定义图层并在其上绘制一个圆圈。我希望能够为圆的半径(以及之后的其他属性)设置动画。根据我的阅读,我设置如下:

Im creating a custom layer and drawing a circle on it. I'd like to be able to animate the radius of the circle (and other properties later). From what i've read, i've set it up like so:

public class CircleLayer : CALayer
{

    //[Export("radius")]
     //public float Radius { get;set; }
    //EDIT: I've now changed the radius field to what is coded below


        public float Radius;

    [Export("radius")]
    public float getRadius()
    {
        return Radius;
    }

    [Export("setRadius:")]
    public void setRadius(float val)
    {
        Radius = val;
    }

    public float Thickness {get;set;}
    public CGColor Color {get;set;}
    public float GlowAmount {get;set;}

    private SizeF GlowOffset {get;set;}

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

        if(key.Equals("radius"))
        {

            return true; 
        }
        else
            return false;

    }



    public CircleLayer ()
    {
        if(GlowAmount == 0.0f)
            GlowAmount = 10f;

        GlowOffset = new SizeF(0f,0f);
        //CALayer.NeedsDisplayForKey("radius");
    }



    public override void DrawInContext (CGContext context)
    {
        base.DrawInContext (context);
        Console.WriteLine("drawing...........");
        PointF centerPoint = new PointF(125,125);//this.Frame.Width/2,this.Frame.Height/2);


        //Outer circle
        context.AddEllipseInRect(new RectangleF(centerPoint.X - Radius,
                                                centerPoint.Y - Radius,
                                                Radius * 2,
                                                Radius * 2));
        //Inner circle
        context.AddEllipseInRect(new RectangleF(centerPoint.X - InnerRadius,
                                                centerPoint.Y - InnerRadius,
                                                InnerRadius * 2,
                                                InnerRadius * 2));

        //Fill in circle
        context.SetFillColor(Color);
        context.SetShadowWithColor(GlowOffset,GlowAmount,GlowColor);
        context.EOFillPath();


    }
}

但它只是不起作用。当调用NeedsDisplayForKey(并将它们打印到控制台)时,我从未获得半径键报告。我可以设置标准属性的动画没问题(例如:缩放)

But it just doesn't work. I never get the radius key reported when NeedsDisplayForKey gets called (and prints them to the console). I can animate standard properties no problem (eg: scale)

编辑:请注意,我现在可以使用SetValueForKey成功修改属性Radius的值。如果我这样做,我需要调用SetNeedsDisplay()来更新屏幕,但是我仍然无法使动画完全正常工作。

Note that I can now successfully modify the value of the property Radius using SetValueForKey. If I do this I need to call SetNeedsDisplay() to update the screen, however i still cannot get the animation to work at all.

编辑#2:示例附件: http://dl.dropbox.com/u/8617393/GraphicsTest1.zip

Edit #2: Sample attached: http://dl.dropbox.com/u/8617393/GraphicsTest1.zip

推荐答案

不幸的是,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.

这篇关于使用Monotouch中的CoreAnimation为自定义属性设置动画效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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