KeyFrame Animations


#1

If you’re wondering why the bounce animation is a little choppy at the start and beginning it’s because the book doesn’t make the first and last keyframes match the model layer’s state. Doing this made the animation look much better:

CAKeyframeAnimation *bounce = [CAKeyframeAnimation animationWithKeyPath:@"transform"]; CATransform3D start = CATransform3DMakeScale(1.0, 1.0, 1.0); CATransform3D forward = CATransform3DMakeScale(1.3, 1.3, 1); CATransform3D back = CATransform3DMakeScale(0.7, 0.7, 1); CATransform3D forward2 = CATransform3DMakeScale(1.2, 1.2, 1); CATransform3D back2 = CATransform3DMakeScale(0.9, 0.9, 1); [bounce setValues:[NSArray arrayWithObjects: [NSValue valueWithCATransform3D:start], [NSValue valueWithCATransform3D:forward], [NSValue valueWithCATransform3D:back], [NSValue valueWithCATransform3D], [NSValue valueWithCATransform3D:back2], [NSValue valueWithCATransform3D:start], nil]];

It’s useful to understand that you don’t get a free animation from the model layer’s state to the first keyframe and from the last keyframe back to the model layer’s state.


#2

My book shows:

  [bounce setValues:[NSArray arrayWithObjects
                      [NSValue valueWithCATransform3D:CATransform3DIdentity],
                      ...
                      [NSValue valueWithCATransform3D:CATransform3DIdentity],
                      nil]];

I think this has the intended effect. (But that’s a good point about noting that the first keyframe represents the actual starting value, not the first target value.)


#3

Oh, ha! I went back and looked. Apparently I copied it incorrectly and missed those, probably because I was operating under the aforementioned false assumption. Thanks :slight_smile:


#4

I should have confessed when I wrote my reply: I did the same thing :slight_smile: