开发者

Can't animate a custom view

开发者 https://www.devze.com 2023-03-04 14:40 出处:网络
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)

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开发者_JAVA技巧 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!


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.


// Create the attributes dictionary for the first view.

        NSMutableDictionary firstViewDict = new NSMutableDictionary ();


        //var firstViewRect = new NSDictionary[] { };
        firstViewDict [NSViewAnimation.TargetKey] = animateWindow;
        firstViewDict [NSViewAnimation.StartFrameKey] = NSValue.FromRectangleF (new RectangleF (1000, 300 , this.Frame.Width - 40, 0));
        firstViewDict [NSViewAnimation.EndFrameKey]  = NSValue.FromRectangleF (SettingNSWindow.Frame);


        //var NSDict = new NSDictionary[]{ };
        NSDictionary[] NSDict =  new NSDictionary[]{firstViewDict};

        //NSDict.Cast(NSMutableDictionary = (NSDictionary[])firstViewDict;

        NSViewAnimation theAnim = new NSViewAnimation(NSDict);

        //theAnim.SetValuesForKeysWithDictionary (firstViewDict);
        theAnim.Duration = 2;
        theAnim.StartAnimation ();
0

精彩评论

暂无评论...
验证码 换一张
取 消