CABasicAnimation学习Demo 包括了一些常用的动画效果(三)

2015-07-24 05:57:55 · 作者: · 浏览: 27
CGContextAddQuadCurveToPoint(context, 10, 450, 310, 450); //CGContextAddQuadCurveToPoint(context, 310, 10, 10, 10); //划线 CGContextDrawPath(context, kCGPathStroke); //得到一个image 从目前的矢量上下文 UIImage *curve = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIImageView *curveView = [[UIImageView alloc]initWithImage:curve]; curveView.frame = CGRectMake(1, 1, 320, 460); [curveView setBackgroundColor:[UIColor clearColor]]; [self.view addSubview:curveView]; } -(void)animateCicleAlongPath { //准备关键帧动画 CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; pathAnimation.calculationMode = kCAAnimationPaced; pathAnimation.fillMode = kCAFillModeForwards; pathAnimation.removedOnCompletion = NO; pathAnimation.duration = 5.0f; pathAnimation.repeatCount = 200; //pathAnimation.autoreverses = YES; //原路返回,而不是从头再来 //设置动画路径 //CGPoint endPoint = CGPointMake(310, 450); CGMutablePathRef curvedPath = CGPathCreateMutable(); CGPathMoveToPoint(curvedPath, NULL, 10, 10); CGPathAddQuadCurveToPoint(curvedPath, NULL, 10, 450, 310, 450); CGPathAddQuadCurveToPoint(curvedPath, NULL, 310, 10, 10, 10); //已经有了路径,我们要告诉动画 路径 pathAnimation.path = curvedPath; CGPathRelease(curvedPath); //这里要手工释放 [self.ViewTest.layer addAnimation:pathAnimation forKey:nil]; } /**************************************************************************/ - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end

最后附上Demo下载地址:http://download.csdn.net/detail/u012951123/7500419