无法为自定义视图设置动画

发布于 2024-11-05 20:42:29 字数 755 浏览 1 评论 0原文

我正在尝试使用以下代码对我的自定义视图的移动进行动画处理(我从 Apple 自己的文档中的 Objective-C 进行的最佳翻译)

        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 ();

但是在运行应用程序时出现以下运行时错误:2011-05-08 00:53:30.827 EpisodeNext[61715:613] [ setValue:forUndefinedKey:]:此类对于键 NSViewAnimationTargetKey 不符合键值编码。

知道我做错了什么吗?谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凤舞天涯 2024-11-12 20:42:29

您无法使用 SetValuesForKeysWithDictionary 方法将动画键传递给 NSViewAnimation 实例。

您必须使用 NSViewAnimation(NSDictionary[] viewAnimations) 构造函数来传递动画字典。

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.

凡间太子 2024-11-12 20:42:29

// 为第一个视图创建属性字典。

        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 ();

// 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 ();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文