Created
December 30, 2013 18:14
-
-
Save ariok/8185619 to your computer and use it in GitHub Desktop.
Animate a property of a layer and implicitly animate the result.
This file contains hidden or 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
@dynamic theProperty; //The property should set as dynamic | |
- (id)initWithLayer:(id)layer { | |
if (self = [super initWithLayer:layer]) { | |
if ([layer isKindOfClass:[PieMask class]]) { | |
YourLayer *currentPresentation = (YourLayer *)layer; | |
self.theProperty = currentPresentation.theProperty; | |
//Add here any other properties needed for the animation | |
//I.E. self.anotherProperty = currentPresentation.anotherProperty; | |
} | |
} | |
return self; | |
} | |
+ (BOOL)needsDisplayForKey:(NSString *)key { | |
if ([key isEqualToString:@"theProperty"]) { | |
return YES; | |
} | |
return [super needsDisplayForKey:key]; | |
} | |
-(id<CAAction>)actionForKey:(NSString *)event { | |
if ([event isEqualToString:@"theProperty"]{ | |
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:event]; | |
anim.fromValue = [[self presentationLayer] valueForKey:event]; | |
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; | |
anim.duration = 1.0; | |
return anim; | |
} | |
return [super actionForKey:event]; | |
} | |
- (void)drawInContext:(CGContextRef)ctx{ | |
// Draw the layer using theProperty... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment