I guess I have to convert the CGRect into an object to pass it to fromValue?
This is how I try it, but it doesn't work:
CABasicAnimation *frameAnimation = [CABasicAnimation animationWithKeyPath:@"frame"];
frameAnimation.duration = 2.5;
frameAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
frameAnimation.fromValue = [NSValue valueWithCGRect:myLayer.frame];
frameAnimation.toValue = [NSValue valueWithCGRect:theNewFrameRect];
[myLayer addAnimation:frameAnimation forKey:@"MLC"];
The frame property of a CALayer is a derived property, dependent on the position, anchorPoint, bounds and transform of the layer. Instead of animating the frame, you should instead animate the position or bounds, depending on what effect you are trying to accomplish.
To move a layer, you can animate the
position
:To resize a layer, you would animate the
bounds
parameter:You can combine these animations using a CAAnimationGroup if you need to move and resize a layer at the same time.
Here's a simple, fully working, example which may help someone.
Just call
.slideUp()
on the class and it will slide up.The question is antique, but I will answer it anyway.
Frame property is not animatable. You have to animate other properties. Also you have to disable implicit animations.
I guess you need to change your last line to make it work:
You may also set an action to the layer to make all frame changes animated with your animation:
In CALayer's
actionForKey:
method reference you can find how layer looks up for the actions to animated its properties.we can change the properties of "bounds" and "position" to animate it, such as