【问题标题】:Can't animate a custom view无法为自定义视图设置动画
【发布时间】:2014-02-22 06:51:18
【问题描述】:

我正在尝试使用以下代码为我的自定义视图的移动设置动画(我最好的翻译自苹果自己的文档的 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。

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

【问题讨论】:

    标签: cocoa macos mono monomac


    【解决方案1】:

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

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

    【讨论】:

    • 不幸的是,这样做我得到以下信息:错误 CS1503: Argument #1' cannot convert MonoMac.Foundation.NSMutableDictionary' expression to type `MonoMac.Foundation.NSCoder' (只需删除 SetValuesForKeysWithDictionary 方法并将 animDict 放入NSViewAnimation 构造函数...)
    • 你试过用“var theAnim = new NSViewAnimation (new NSMutableDictionary[]{ animDict });” ?
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-12
      • 1970-01-01
      • 1970-01-01
      • 2012-03-12
      • 2016-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多