Last active
January 2, 2016 22:09
-
-
Save holysin/8368211 to your computer and use it in GitHub Desktop.
CALayer Basic Animation
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 <QuartzCore/QuartzCore.h> | |
@interface CALayer (RNAnimations) | |
- (void)setValue:(id)value forKeyPath:(NSString *)keyPath duration:(CFTimeInterval)duration delay:(CFTimeInterval)delay; | |
@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 "CALayer+RNAnimations.h" | |
@implementation CALayer (RNAnimations) | |
- (void)setValue:(id)value forKeyPath:(NSString *)keyPath duration:(CFTimeInterval)duration delay:(CFTimeInterval)delay | |
{ | |
[CATransaction begin]; | |
[CATransaction setDisableActions:YES]; | |
[self setValue:value forKeyPath:keyPath]; | |
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:keyPath]; | |
anim.duration = duration; | |
anim.beginTime = CACurrentMediaTime() + delay; | |
anim.fillMode = kCAFillModeBoth; | |
anim.fromValue = [[self presentationLayer] valueForKeyPath:keyPath]; | |
anim.toValue = value; | |
[self addAnimation:anim forKey:keyPath]; | |
[CATransaction commit]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment