Skip to content

Instantly share code, notes, and snippets.

@holysin
Last active January 2, 2016 22:09
Show Gist options
  • Save holysin/8368211 to your computer and use it in GitHub Desktop.
Save holysin/8368211 to your computer and use it in GitHub Desktop.
CALayer Basic Animation
#import <QuartzCore/QuartzCore.h>
@interface CALayer (RNAnimations)
- (void)setValue:(id)value forKeyPath:(NSString *)keyPath duration:(CFTimeInterval)duration delay:(CFTimeInterval)delay;
@end
#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