2012-03-03 12 views
3

これは本質的にここに掲示されたものと同じ質問です:Animating a custom property in a CALayer 1年以上前と答えられていません。MonotouchでCoreAnimationを使用してカスタムプロパティをアニメーション化しますか?

カスタムレイヤーを作成し、それに円を描画します。私は円の半径をアニメートできるようにしたいと思います。私が読んだことから、私はそれを次のように設定しました:

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が呼び出されたときに報告されたradiusキーが決して得られない(そして、それらをコンソールに表示する)。私は標準的なプロパティをアニメーション化できます(スケールなど)

編集:SetValueForKeyを使用してRadiusプロパティの値を正常に変更できるようになりました。私はこれを行う場合は、画面を更新するためにSetNeedsDisplay()を呼び出す必要がありますが、私はまだアニメーションをまったく動作させることができません。

編集#2:付属のサンプル:http://dl.dropbox.com/u/8617393/GraphicsTest1.zip

+0

サンプル全体を投稿してもよろしいですか? –

+0

こんにちは、ありがとうございました。私はサンプルプロジェクトへのリンクを含めるように質問を編集しました – Dermot

答えて

2

これは残念ながらMonoTouchでで行うことは不可能であった - しかし、我々がうまくいけば、すぐにリリースされる予定の次のベータ版(5.3.3)のためにそれを修正しました。

5.3.3がリリースされたら、このサンプルを使用することができます:https://github.com/xamarin/monotouch-samples/tree/monotouch-5.4/CustomPropertyAnimationこれを行う方法。

+0

私はそれを知っていました! :-)しかし、更新のおかげで。 – Dermot

関連する問題