kaal101
kaal101

Reputation: 664

Resize NSWindows with easing animation

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?

Upvotes: 17

Views: 9067

Answers (2)

Anne
Anne

Reputation: 27073

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

Upvotes: 38

Thomas Abplanalp
Thomas Abplanalp

Reputation: 5

[[NSWindow animator] setAlphaValue:0.0];

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

Upvotes: -6

Related Questions