Reputation: 16022
**Note: This is for iOS, not OS X, so implicit animations aren't automatically set up.
I am trying to add implicit animation to a CALayer for the position property.
My (incorrect) code is this:
NSMutableDictionary * actions = [self.view.layer.actions mutableCopy ] ;
if ( !actions ) { actions = [ NSMutableDictionary dictionary ] ; }
CABasicAnimation * anim = [ CABasicAnimation animationForKeyPath:@"position" ] ;
[ actions setValue:anim forKey:@"position" ] ;
self.view.layer.actions = actions ;
My question is, what sort of animation (the anim property, above) i.e. CABasicAnimation
, CATransition
should I use for this scenario and how should I configure it?
Grazie
Upvotes: 0
Views: 457
Reputation: 735
Implicit animations, are triggered by just setting the position property (i.e self.view.layer.position = <new position>;
) and Quartz will take care of the rest using your current CATransaction setting.
If you want to use explicit animation (which you seem to be trying to do), I would use CABasicAnimation and do something like this.
self.view.layer.position = <new position>;
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
animation.duration = <duration>;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
animation.fromValue = <current position>;
animation.toValue = <new position>;
[line addAnimation:animation forKey:@"position"];
Upvotes: 1