Skip to content

Instantly share code, notes, and snippets.

@ccgus
Created January 16, 2013 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccgus/4544658 to your computer and use it in GitHub Desktop.
Save ccgus/4544658 to your computer and use it in GitHub Desktop.
FMSimpleBlockAnimation
#import <Cocoa/Cocoa.h>
@interface FMSimpleBlockAnimation : NSAnimation {
void (^_animationBlock)(float t);
}
- (void)animateWithBlock:(void(^)(float t))block;
@end
#import "FMSimpleBlockAnimation.h"
@implementation FMSimpleBlockAnimation
- (void)animateWithBlock:(void(^)(float t))block {
_animationBlock = [block copy];
[self startAnimation];
}
- (void)setCurrentProgress:(NSAnimationProgress)progress {
if (_animationBlock) {
_animationBlock(progress);
}
}
@end
@ccgus
Copy link
Author

ccgus commented Jan 16, 2013

FMSimpleBlockAnimation *a = [[FMSimpleBlockAnimation alloc] initWithDuration:.25 animationCurve:NSAnimationEaseIn];

[a setFrameRate:60];
[a setAnimationBlockingMode:NSAnimationNonblocking];
[a animateWithBlock:^(float t) {
    _fadeInOpacity = t;
    [self setNeedsDisplay:YES];
}];

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