Resize NSWindows with easing animation

血红的双手。 提交于 2019-11-28 18:05:57

问题


I'm trying to resize an NSWindow (the main one) with a nice easing animation (EaseOut).

I can use the [NSWindow animator] but I havn't found a way to add the easing effect.

Do you have an idea or code sample which can help me to do that?


回答1:


Option 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];

Option 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]; 



回答2:


[[NSWindow animator] setAlphaValue:0.0];

Don't forget to set the alpha value to 1.0 when you want to show the window again.



来源:https://stackoverflow.com/questions/6225398/resize-nswindows-with-easing-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!