2011-02-12 73 views
3

我試圖讓CALayer中的自定義屬性在動畫上工作。在CALayer中爲自定義屬性設置動畫

但我只是無法弄清楚如何讓這個工作正常。關鍵「myCounter」永遠不會發送到NeedsDisplayForKey。有沒有我失蹤的一些步驟?以下是我正在測試的課程,我將其添加到別處的圖層中。有沒有人有一個自定義屬性使用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; 

    } 
    } 
+0

你有沒有解決這個問題? – Dermot 2012-03-03 08:01:11

回答

0

的MonoTouch不具有相同的自動註冊KVC支持,擁有的MonoMac還沒有,所以你應該使用:

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

謝謝,我已經做了這個改變,但那個關鍵仍然沒有傳遞給NeedsDisplayForKey。該方法打印出一長串動畫鍵,而不是新的動畫鍵。 – addr010 2011-02-12 04:17:29