Skip to content

Instantly share code, notes, and snippets.

@indragiek
Created November 27, 2011 05:55
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save indragiek/1397050 to your computer and use it in GitHub Desktop.
Save indragiek/1397050 to your computer and use it in GitHub Desktop.
NSWindow+Fade - Animator proxy based NSWindow fading
@interface NSWindow (Fade)
- (IBAction)fadeIn:(id)sender;
- (IBAction)fadeOut:(id)sender;
@end
#import "NSWindow+SNRAdditions.h"
#define kWindowAnimationDuration 0.1f
@implementation NSWindow (Fade)
- (IBAction)fadeIn:(id)sender
{
[self setAlphaValue:0.f];
[self makeKeyAndOrderFront:nil];
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:kWindowAnimationDuration];
[[self animator] setAlphaValue:1.f];
[NSAnimationContext endGrouping];
}
- (IBAction)fadeOut:(id)sender
{
[NSAnimationContext beginGrouping];
__block __unsafe_unretained NSWindow *bself = self;
[[NSAnimationContext currentContext] setDuration:kWindowAnimationDuration];
[[NSAnimationContext currentContext] setCompletionHandler:^{
[bself orderOut:nil];
[bself setAlphaValue:1.f];
}];
[[self animator] setAlphaValue:0.f];
[NSAnimationContext endGrouping];
}
@end
@KyLeggiero
Copy link

KyLeggiero commented Nov 12, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment