Skip to content

Instantly share code, notes, and snippets.

@vienvu89
Created July 11, 2017 06:24
Show Gist options
  • Save vienvu89/8af47d792e2bf3bc5bd2ea487817dc95 to your computer and use it in GitHub Desktop.
Save vienvu89/8af47d792e2bf3bc5bd2ea487817dc95 to your computer and use it in GitHub Desktop.
- (id<CAAction>)actionForLayer:(CALayer *)layer forKey:(NSString *)event {
if (layer == self.shapeLayer && [event isEqualToString:@"strokeEnd"]) {
//Only perform animation action when in a UIView animation block
CAAnimation *opacityAction = (id)[super actionForLayer:layer forKey:@"opacity"];
if (opacityAction && ![opacityAction isKindOfClass:[NSNull class]] && [opacityAction isKindOfClass:[CAAnimation class]]) {
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:event];
animation.fromValue = [layer.presentationLayer valueForKey:event];
animation.duration = opacityAction.duration;
return animation;
} else {
return [NSNull null];
}
}
return [super actionForLayer:layer forKey:event];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment