通过简化动画调整NSWindows的大小

时间:2011-06-03 09:40:21

标签: cocoa core-animation nswindow

我正试图通过一个很好的缓动动画(EaseOut)来调整NSWindow(主要的)的大小。

我可以使用[NSWindow animator],但我找不到添加缓动效果的方法。

您是否有想法或代码示例可以帮助我做到这一点?

2 个答案:

答案 0 :(得分:32)

选项1

float Y = 100;
float X = 200;

NSRect frame = [window frame];

frame.origin.y -= Y;
frame.size.height += Y;
frame.size.width += X;

[window setFrame:frame display:YES animate:YES];

选项2

float Y = 100;
float X = 200;

NSRect frame = [window frame];

frame.origin.y -= Y;
frame.size.height += Y;
frame.size.width += X;

NSDictionary *windowResize = @{
    NSViewAnimationTargetKey: window,
    NSViewAnimationEndFrameKey: [NSValue valueWithRect:frame]
};
NSDictionary *oldFadeOut = @{
    NSViewAnimationTargetKey: [NSNull null],
    NSViewAnimationEffectKey: NSViewAnimationFadeOutEffect
};
NSDictionary *newFadeIn = @{
    NSViewAnimationTargetKey: [NSNull null],
    NSViewAnimationEffectKey: NSViewAnimationFadeInEffect
};

NSArray *animations = @[windowResize, newFadeIn, oldFadeOut];
NSViewAnimation *animation = [[NSViewAnimation alloc] initWithViewAnimations: animations];

[animation setAnimationBlockingMode: NSAnimationBlocking];
[animation setAnimationCurve: NSAnimationEaseIn];
[animation setDuration: 2];     
[animation startAnimation]; 

答案 1 :(得分:-4)

[[NSWindow animator] setAlphaValue:0.0];

当您想再次显示窗口时,不要忘记将alpha值设置为1.0。