Created
February 12, 2015 07:54
-
-
Save BichengLUO/74cb6f4e8f658f6d9cda to your computer and use it in GitHub Desktop.
UIView animation along a round path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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