Created
March 19, 2015 22:21
-
-
Save QuynhNguyen/d001fc0a4148996a0ff9 to your computer and use it in GitHub Desktop.
Custom CALayerAnimation
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
@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