cocoa专门为视图和窗口动画提供了一个NSAnimation的子类:NSViewAnimation。通过设置属性字典就可以对窗口进行大小、位置、显示隐藏等动画。

 1 //使用NSViewAnimation
 2 - (IBAction)didViewAnimateClicked:(id)sender {
 3     //获取当前窗口大小
 4     NSRect firstFrame = [[NSApp mainWindow] frame];
 5     
 6     //属性字典
 7     NSMutableDictionary *dict = [NSMutableDictionary dictionary];
 8     
 9     //设置目标对象
10     [dict setObject:[NSApp mainWindow] forKey:NSViewAnimationTargetKey];
11     
12     //设置其实大小
13     [dict setObject:[NSValue valueWithRect:firstFrame] forKey:NSViewAnimationStartFrameKey];
14     
15     firstFrame.size.width = 50;
16     firstFrame.size.height = 50;
17     
18     //设置最终大小
19     [dict setObject:[NSValue valueWithRect:firstFrame] forKey:NSViewAnimationEndFrameKey];
20     
21     //设置动画效果
22     [dict setObject:NSViewAnimationFadeOutEffect forKey:NSViewAnimationEffectKey];
23     
24     //设置动画
25     NSViewAnimation *animation = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict]];
26     
27     //启动动画
28     [animation startAnimation];
29 }

 

posted on 2013-12-27 14:33  排云鹤  阅读(2158)  评论(0编辑  收藏  举报