I am trying to animate a custom property on CALayer with implicit animation:
[UIView animateWithDuration:2.0f animations:^{ self.imageView.myLayer.myProperty = 1; }]
In -actionForKey: method I need to return the animation, taking care of the interpolation of the values. Of course, I need to somehow tell the animation how to get other parameters for the animation (i.e. duration and synchronization function ).
- (id<CAAction>)actionForKey:(NSString *)event { if ([event isEqualToString:@"myProperty"]) { CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"myProperty"]; [anim setFromValue:@(self.myProperty)]; [anim setKeyPath:@"myProperty"]; return anim; } return [super actionForKey:event]; } }
Any idea on how to achieve this? I tried to find the animation in the layer properties, but could not find anything interesting. I also have a problem with layer animations, since actionForKey: is called outside of animations.
ios core-animation calayer
Fr4ncis
source share