views:

196

answers:

1

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"];
+1  A: 

I guess you need to change your last line to make it work:

[myLayer addAnimation:frameAnimation forKey:@"frame"];

You may also set an action to the layer to make all frame changes animated with your animation:

CABasicAnimation *frameAnimation = [CABasicAnimation animation];
frameAnimation.duration = 2.5;
frameAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

myLayer.actions = [NSDictionary dictionaryWithObjectsAndKeys:frameAnimation, @"frame", nil];

In CALayer's actionForKey: method reference you can find how layer looks up for the actions to animated its properties.

Vladimir
Thanks Vladimir. I have found that CALayer can't animate the frame property directly. The documentation says that in a gray box. Haven't seen it for some reason.
dontWatchMyProfile