Last active
January 22, 2017 03:42
-
-
Save jawj/4577793b12bf85e77677 to your computer and use it in GitHub Desktop.
An easing category on CAMediaTimingFunction, with thanks to Mozilla
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
// | |
// CAMediaTimingFunction+GMTimingBlock.h | |
// | |
// Created by George MacKerron on 2015/06/11. | |
// Copyright (c) 2015 George MacKerron. All rights reserved. | |
// | |
#import <QuartzCore/QuartzCore.h> | |
typedef CGFloat (^GMTimingBlock)(CGFloat); | |
@interface CAMediaTimingFunction (GMTimingBlock) | |
- (GMTimingBlock)gm_timingBlock; | |
@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
// | |
// CAMediaTimingFunction+GMTimingBlock.mm | |
// | |
// Created by George MacKerron on 2015/06/11. | |
// Copyright (c) 2015 George MacKerron. All rights reserved. | |
// | |
#import "CAMediaTimingFunction+GMEasingBlock.h" | |
#import "nsSMILKeySpline.h" | |
@implementation CAMediaTimingFunction (GMTimingBlock) | |
- (GMTimingBlock)gm_timingBlock { | |
float coords[4]; | |
[self getControlPointAtIndex:1 values:coords]; | |
[self getControlPointAtIndex:2 values:coords + 2]; | |
nsSMILKeySpline* ks = new nsSMILKeySpline(coords[0], coords[1], coords[2], coords[3]); | |
return ^(CGFloat x) { | |
return ks->GetSplineValue(x); | |
}; | |
} | |
@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
Add these source files to your project: | |
https://dxr.mozilla.org/mozilla-central/source/dom/smil/nsSMILKeySpline.h | |
https://dxr.mozilla.org/mozilla-central/source/dom/smil/nsSMILKeySpline.mm | |
Comment out two includes in nsSMILKeySpline.h, which appear to be unused: | |
// #include "mozilla/ArrayUtils.h" | |
// #include "mozilla/PodOperations.h" | |
Then use like this: | |
#import "CAMediaTimingFunction+GMTimingBlock.h" | |
// ... | |
GMTimingBlock ease = [[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut] gm_timingBlock]; | |
NSLog(@"%f, %f, %f, %f, %f, %f", ease(0.0f), ease(0.2f), ease(0.4f), ease(0.6f), ease(0.8f), ease(1.0f)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment