UIView animation in a circular path?

I need my little guy (in UIIamgeView) to jump forward and it should look natural. I want to know if there is a way to do this using CoreAnimation (beginAnimation / commitAnimation)?

I could do this by setting a point between them in the air, but the movement looks unnatural: P

+4
source share
3 answers

Reading a post by Brad Larson, I ended up with a nice feature to make my image the next round.

You need to import the QuartzCore framework: #import

Here is the code:

// Set up path movement CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; pathAnimation.calculationMode = kCAAnimationPaced; pathAnimation.fillMode = kCAFillModeForwards; pathAnimation.removedOnCompletion = NO; pathAnimation.repeatCount = INFINITY; //pathAnimation.rotationMode = @"auto"; pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; pathAnimation.duration = 5.0; // Create a circle path CGMutablePathRef curvedPath = CGPathCreateMutable(); CGRect circleContainer = CGRectMake(0, 0, 400, 400); // create a circle from this square, it could be the frame of an UIView CGPathAddEllipseInRect(curvedPath, NULL, circleContainer); pathAnimation.path = curvedPath; CGPathRelease(curvedPath); [self.imageView.layer addAnimation:pathAnimation forKey:@"myCircleAnimation"]; 
+13
source

To follow Ole's answer, my answer to this question provides code for executing such animation curves using CAKeyframeAnimation.

+3
source

Create a CAKeyframeAnimation and assign CGPath to your path property.

+2
source

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


All Articles