OC动画:CAKeyframeAnimation
Posted hualuoshuijia
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OC动画:CAKeyframeAnimation相关的知识,希望对你有一定的参考价值。
// 方法一 用法1? Value方式 //创建动画对象 CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; //设置value NSValue *value1=[NSValue valueWithCGPoint:CGPointMake(100, 100)]; NSValue *value2=[NSValue valueWithCGPoint:CGPointMake(200, 100)]; NSValue *value3=[NSValue valueWithCGPoint:CGPointMake(100, 200)]; NSValue *value4=[NSValue valueWithCGPoint:CGPointMake(200, 200)]; NSValue *value5=[NSValue valueWithCGPoint:CGPointMake(100, 300)]; NSValue *value6=[NSValue valueWithCGPoint:CGPointMake(200, 300)]; [email protected][value1,value2,value3,value4,value5,value6]; //重复次数 默认为1 // animation.repeatCount=MAXFLOAT; //设置是否原路返回默认为不 // animation.autoreverses = YES; //设置移动速度,越小越快 animation.duration = 4.0f; animation.removedOnCompletion = NO; animation.fillMode = kCAFillModeForwards; animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; animation.delegate=self; //给这个view加上动画效果 [redView.layer addAnimation:animation forKey:nil];
CAKeyframeAnimation *keyframeAnimation=[CAKeyframeAnimation animationWithKeyPath:@"position"]; // 创建一个CGPathRef对象,就是动画的路线 CGMutablePathRef path = CGPathCreateMutable(); // 设置开始位置 CGPathMoveToPoint(path, NULL, redView.layer.position.x-40, redView.layer.position.y+40);//移动到起始点 // 沿着路径添加四曲线点移动 CGPathAddQuadCurveToPoint(path, NULL, 100, 100, self.view.frame.size.width, 0); keyframeAnimation.path = path; keyframeAnimation.delegate = self; CGPathRelease(path); keyframeAnimation.duration = 7; [redView.layer addAnimation:keyframeAnimation forKey:@"KCKeyframeAnimation_Position"];
以上是关于OC动画:CAKeyframeAnimation的主要内容,如果未能解决你的问题,请参考以下文章
为啥我不能使用 CAKeyframeAnimation 在 eulerAngle 上为 SCNnode 设置动画
ios之CAKeyframeAnimation关键帧动画详解
核心动画(CAKeyframeAnimation,CABasicAnimation)
如何同步几个不同图层的 CAKeyframeAnimation 动画?