Hi, I’m trying to make a window fade in when
makeKeyAndOrderFront
is used and fade out when the window is closed.
I did actually ask this question on Stack Overflow - http://stackoverflow.com/questions/4547889/window-fade-in-and-out , I got an answer, but I don’t know much Obj-C and the code didn’t really work, the way I was using it or something.
Could anyone help me to do this in ASOC ? (The code at SO might help)
Show us the code you’ve tried.
It’s over on Stack Overflow, link in my first post…
- (void)fadeInAndMakeKeyAndOrderFront:(BOOL)orderFront {
[self setAlphaValue:0.0];
if (orderFront) {
[self makeKeyAndOrderFront:nil];
}
[[self animator] setAlphaValue:1.0];
}
- (void)fadeOutAndOrderOut:(BOOL)orderOut {
if (orderOut) {
NSTimeInterval delay = [[NSAnimationContext currentContext] duration] + 0.1;
[self performSelector:@selector(orderOut:) withObject:nil afterDelay:delay];
}
[[self animator] setAlphaValue:0.0];
}
I just put this in an Obj-C class and made it the window’s delegate.
Just do it in ASObjC. When you want to close a window, do something like:
set theDelay to current application's NSAnimationContext's currentContext()'s duration()
tell theWindow
tell animator() to setAlphaValue_(0)
performSelector_withObject_afterDelay_("orderOut:", missing value, theDelay + 0.1)
end tell
That starts the animation, and closes the window just after it finishes. When you want to open a window, use something like this:
tell theWindow
setAlphaValue_(0)
-- open it in here
tell animator() to setAlphaValue_(1)
end tell
Oh right, ok, thanks!
I’ve tried fade in and fade out both work!
Thanks again!