553CAAnimation and the Snapback Problem

Having previously done Core Animation only on the iPhone, I am still a beginner when it comes dealing with in on OSX.

The first thing that surprised me, is that layers have implicit animations; meaning whenever you change a value, the layer will animate to it using certain defaults. (duration = 0.25, etc.) While it is nice, I am still looking for a way to control it.

When you want to know, when an animation is finished, you need to make a CAAnimation, set the delegate and let it call animationDidStop:

CAAnimationGroup *group = [CAAnimationGroup animation];
group.delegate = self;
group.duration = 0.25;
group.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];

CABasicAnimation *position = [CABasicAnimation animationWithKeyPath:@"position"];
position.fromValue = fromPointValue;
position.toValue = toPointValue;

CABasicAnimation *opacity = [CABasicAnimation animationWithKeyPath:@"opacity"];
opacity.fromValue = [NSNumber numberWithFloat:1.0];
opacity.toValue = [NSNumber numberWithFloat:0.0];

group.animations = [NSArray arrayWithObjects:position, opacity, nil];

[removeTarget addAnimation:group forKey:@"group"];

While this animates nicely, it still is not quite right. Because the layer basically does not know, that it values are changed in the animation, and therefore, after the animation stopped, the values are reset to the ones BEFORE the animation.

That's the annoying snapback.

To get rid of it, tell the layer the new values, right after you add the animation.

removeTarget.opacity = 0.0;
removeTarget.position = toPointValue;

%nbsp;

Interesting to see, that others seem to go throught the same learning experience.

379Never use a beta SDK for active development

As seen in iPhone SDK 3.2 beta 2 and the "A signed resource has been added, modified, or deleted." error message.

Solution? Switch back to iPhone SDK 3.1.3 with XCode 3.2.1

Apparently several different versions of XCode (and the Developer Folder) can happily coexist. Just rename one DeveloperBeta or something like that...