Resize NSWindows with easing animation

一世执手 提交于 2019-11-29 21:06:09
Anne

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]; 
[[NSWindow animator] setAlphaValue:0.0];

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

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