NSViewAnimation進行視圖和窗口動畫

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 }
相關文章
相關標籤/搜索