Skip to content

Instantly share code, notes, and snippets.

@natevw
Last active March 14, 2016 23:10
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 natevw/5927714adc8c58857533 to your computer and use it in GitHub Desktop.
Save natevw/5927714adc8c58857533 to your computer and use it in GitHub Desktop.
Hook this up to a coupla text boxes and see NSAnimation only ever do 60fps, picture of sample interface at https://twitter.com/natevw/status/709516893917319168
@interface MyAnimation : NSAnimation {}
@property NSUInteger frameCount;
@end
@implementation MyAnimation
- (void)startAnimation {
_frameCount = 0;
[super startAnimation];
}
- (void)setCurrentProgress:(NSAnimationProgress)progress {
[super setCurrentProgress:progress];
NSLog(@"Progress: %f", progress);
_frameCount += 1;
}
@end
@interface AppDelegate () <NSAnimationDelegate>
@property (weak) IBOutlet NSWindow *window;
@property (weak) IBOutlet NSTextField *display;
@property MyAnimation *animation;
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
self.animation = [[MyAnimation alloc] init];
self.animation.duration = 1;
self.animation.animationBlockingMode = NSAnimationNonblockingThreaded;
self.animation.delegate = self;
}
- (IBAction)updateFrameRate:(id)sender {
NSTextField* input = sender;
NSLog(@"New frame rate: %li", input.integerValue);
[self.animation stopAnimation];
self.animation.currentProgress = 0;
self.animation.frameRate = input.integerValue;
[self.animation startAnimation];
self.display.stringValue = @"-";
}
- (void)animationDidEnd:(NSAnimation *)animation {
self.display.integerValue = (NSInteger)self.animation.frameCount;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment