views:

194

answers:

2

This is probably a simple question but I can't seem to figure out how to do it. Basically all I want to do is fade a window before closing it:

[[window animator] setAlphaValue:0.0];
[window close];

This works fine without the [window close], but when that is included the window seems to close it before the animation finishes (which is obviously not what I want); the same seems to happen for orderOut:, performClose:, etc. Is there any way to avoid this?

+2  A: 

Implicit animations triggered through the animator proxy run on wall time. Get the duration from the current NSAnimationContext and perform delay your cleanup/post-animation operations using that interval.

Jim Correia
+2  A: 
[[window animator] setAlphaValue:0.0];
[window performSelector:@selector(performClose:) withObject:self afterDelay:[[NSAnimationContext currentContext] duration]];
Tom Dalling
The message to the currentContext should be -animationDuration, not -delay.
kperryua
Thanks. I ended up using this: [window performSelector:@selector(close) withObject:nil afterDelay:[[NSAnimationContext currentContext] duration]];
Michael
D'oh! That's right.. my bad. :-)
kperryua
Thanks kperryua and Michael. I fixed the answer.
Tom Dalling