Search code examples
cocoamacosmonomonomac

Can't animate a custom view


I'm trying to animate the movement of a custom view of mine using the following code (my best translation from objective-c from Apples own documents)

        var animDict = new NSMutableDictionary ();
        animDict [NSViewAnimation.TargetKey] = this.View;
        animDict [NSViewAnimation.StartFrameKey] = NSValue.FromRectangleF (this.View.Frame);
        animDict [NSViewAnimation.EndFrameKey] = NSValue.FromRectangleF (new RectangleF (0, 150 * index, 400, 150));

        var theAnim = new NSViewAnimation ();
        theAnim.SetValuesForKeysWithDictionary (animDict);
        theAnim.Duration = 2;
        theAnim.StartAnimation ();

However I get the following run-time error when running the app: 2011-05-08 00:53:30.827 EpisodeNext[61715:613] [ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key NSViewAnimationTargetKey.

Any idea what I'm doing wrong? Thanx!


Solution

  • You cannot use the method SetValuesForKeysWithDictionary to pass the animation keys to the NSViewAnimation instance.

    You must use the NSViewAnimation(NSDictionary[] viewAnimations) constructor to pass the animation dictionary.