2011-05-07 87 views
2

我尝试使用下面的代码进行动画我的自定义视图的运动(从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密钥的关键值编码。

任何想法我做错了什么?感谢名单!

回答

3

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

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

+0

Unfortuanettly做,我得到如下:错误CS1503:参数'#1' 不能转换'MonoMac.Foundation.NSMutableDictionary“表情输入'MonoMac.Foundation.NSCoder”(简单地删除SetValuesForKeysWithDictionary方法,并把animDict在NSViewAnimation的构造函数中...) – 2011-05-09 12:10:12

+0

您是否尝试过使用“var theAnim = new NSViewAnimation(new NSMutableDictionary [] {animDict});” ? – 2011-05-09 12:30:12

+0

这工作......虽然非常奇怪的语法(在我看来) – 2011-05-09 13:20:51

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