Skip to content

Instantly share code, notes, and snippets.

@BichengLUO
Created February 12, 2015 07:54
Show Gist options
  • Save BichengLUO/74cb6f4e8f658f6d9cda to your computer and use it in GitHub Desktop.
Save BichengLUO/74cb6f4e8f658f6d9cda to your computer and use it in GitHub Desktop.
UIView animation along a round path
// 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"];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment