CAKeyframeAnimation - Examples
I have a a menu that is a CALayer that will slide across the screen to a given point. I want the effect where the menu will go a little past the point, then a little before the point, and then land on the point. I can move the menu by applying a transform, but I was hoping to get this bouncing effect to work. I was开发者_运维知识库 looking into CAKeyframeAnimation, but I'm having trouble locating an example/tutorial. I've looked at the CA Programming Guide but haven't really found anything. Any links or help would be great. Thanks.
I released some code a while ago that does just what you're looking for. Basically, you need to generate your own CGPathRef
containing all of the points you want the layer to hit, and use that path for the path
attribute of the CAKeyframeAnimation
. The code will look something like this:
CGPoint path[3] = {
FTAnimationOutOfViewCenterPoint(enclosingView.bounds, view.frame, view.center, direction),
[self overshootPointFor:view.center withDirection:direction threshold:(overshootThreshold_ * 1.15)],
view.center
};
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
CGMutablePathRef thePath = CGPathCreateMutable();
CGPathAddLines(thePath, NULL, path, 3);
animation.path = thePath;
CGPathRelease(thePath);
The whole method is here.
精彩评论