So good that you figured it out here, but your answer to your question has some inaccuracies. Let me fix a few things:
The frame property can be animated - just not with explicit animation. If you do the following on a layer other than the root layer of the view, the frame will animate just fine:
[CATransaction begin]; [CATransaction setAnimationDuration:2.0f]; [animationLayer setFrame:CGRectMake(100.0f, 100.0f, 100.0f, 100.0f)]; [CATransaction commit];
Remember that setting a property on a layer will animate this property by default. In fact, you need to disable the animation when changing properties, if you do not want it to be animated. (Of course, this is only true if you are animating a layer other than the root level of the view.) You use animation correctly both in position and in borders if you need to use explicit animation.
You can animate a frame on a UIView using implicit animation:
[UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:3.0f]; [[self view] setFrame:CGRectMake(45.0f, 45.0f, 100.0f, 100.0f)]; [UIView commitAnimations];
This will be animated from the current frame of the frame (borders and position) to x = 45.0, y = 45.0, w = 100.0, h = 100.0.
You also may not understand the difference between the animation and the layer. You add animation to layers, but adding animation to a layer does not automatically set the property that you are animating.
CALayers are model objects. They contain information about the layer that ultimately appears on the screen. You must set the layer property if you want this property to really have this value. If you just animate a property, it will only be a visual representation, not an actual one - that is why this value returns to the original value of the layer, because you never changed it.
This leads me to the next point. You said:
Use "animation.removedOnCompletion = NO; animation.fillMode = kCAFillModeForwards;" to ensure that values are not reset at the end of the animation
This is not entirely correct. These two values simply make the animation stay in the final position visually , however the actual values of the layer have not changed. They are still the same values that were when starting the animation. In the general case (with some exceptions) you do not want to use these two parameters, because they are only for visualization . What you want is to set the level value for the property that you are animating.
Say, for example, that you want to animate the position of your layer using explicit animation. Here is the code you want:
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"]; [animation setFromValue:[NSValue valueWithCGPoint:CGPointMake(70.0f, 70.0f)]]; [animation setToValue:[NSValue valueWithCGPoint:CGPointMake(150.0f, 150.0f)]]; [animation setDuration:2.0f];
You can also consider animating animations. With an animation group, you can group several animations together, and then control how they relate to each other. In your case, the duration of your estimates and position animation is the same, and therefore, what you are trying to do works fine without a group, but if you want to compensate for the beginning of the animation, for example, you do not want the position of the animation to start before the second or two in frame animation, you can shake them by setting the beginTime value of the animation position.
Finally, I would be interested to know why you cannot use the implicit animations available in UIView. I use them in the vast majority of Core Animation code that I write, and I can’t understand why this will not work for your situation.
Sincerely.