Window Fade in and Out
how do I fade a window in when it's opened and out when closed?
This should probably be done in Objective C. This has to be part of an AppleScript-Objective-C project. I'm using a property linked to开发者_如何学JAVA the window, and doing makeKeyAndOrderFront on it...
Any help would be appreciated!
Subclass (or add a category to) NSWindow and add:
- (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];
}
This allows you to fade in/out windows programmatically.
To have a window fade out when its close button gets pushed, add this to the window's delegate:
- (BOOL)windowShouldClose:(id)sender {
[window fadeOutAndOrderOut:YES];
return NO;
}
To show a window with fade-in call [window fadeInAndMakeKeyAndOrderFront:YES];
instead of what you'd call otherwise.
精彩评论