Created
November 27, 2011 05:55
-
-
Save indragiek/1397050 to your computer and use it in GitHub Desktop.
NSWindow+Fade - Animator proxy based NSWindow fading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface NSWindow (Fade) | |
- (IBAction)fadeIn:(id)sender; | |
- (IBAction)fadeOut:(id)sender; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Swift 4 version: https://gist.github.com/BenLeggiero/1ec89e5979bf88ca13e2393fdab15ecc