CAKeyframeAnimation - examples

I have a menu that is a CALayer that will move around the screen to a given point. I need an effect when the menu goes a little past the point, then a little to the point, and then lands on the point. I can move the menu using the transform, but I was hoping this bounce effect would work. I studied CAKeyframeAnimation, but it is hard for me to find an example / tutorial. I looked at the CA Programming Guide, but found nothing. Any links or help would be great. Thank.

+3
source share
1 answer

I released some code a while ago that does exactly what you are looking for. Basically, you need to create your own CGPathRef, containing all the points that you want to apply a layer on, and use this path for the attribute path 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 .

+4
source

Source: https://habr.com/ru/post/1741022/


All Articles