Skip to content

Instantly share code, notes, and snippets.

@QuynhNguyen
Created March 19, 2015 22:21
Show Gist options
  • Save QuynhNguyen/d001fc0a4148996a0ff9 to your computer and use it in GitHub Desktop.
Save QuynhNguyen/d001fc0a4148996a0ff9 to your computer and use it in GitHub Desktop.
Custom CALayerAnimation
@implementation CustomAnimationLayer
@dynamic changingProperty1, changingProperty2;
-(CABasicAnimation *)makeAnimationForKey:(NSString *)key {
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:key];
anim.fromValue = [[self presentationLayer] valueForKey:key];
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
anim.duration = kSomeDuration;
return anim;
}
-(id<CAAction>)actionForKey:(NSString *)event {
if ([event isEqualToString:@"changingProperty1"] ||
[event isEqualToString:@"changingProperty2"]) {
return [self makeAnimationForKey:event];
}
return [super actionForKey:event];
}
- (id)initWithLayer:(id)layer {
if (self = [super initWithLayer:layer]) {
//copy layer property to self here
}
return self;
}
+ (BOOL)needsDisplayForKey:(NSString *)key {
if ([key isEqualToString:@"changingProperty1"] || [key isEqualToString:@"changingProperty2"]) {
return YES;
}
return [super needsDisplayForKey:key];
}
-(void)drawInContext:(CGContextRef)ctx {
// Update Context here
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment