Last active
March 14, 2016 23:10
-
-
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
This file contains hidden or 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 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