动画效果
Posted 菜鸟好笨笨!
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了动画效果相关的知识,希望对你有一定的参考价值。
1、实现自身旋转动画效果
不断调用自身这个函数,来实现不停的旋转
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.1];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(startAnimation)];
angle2 += 0.5;
circular2.layer.anchorPoint = CGPointMake(0.5,0.5);//以右下角为原点转,(0,0)是左上角转,(0.5,0,5)心中间转,其它以此类推
circular2.transform = CGAffineTransformMakeRotation(angle2 * (-M_PI / 180.0f));
//不断调用自身方法,实现无限循环旋转,则不需要写下边这一句,如果只执行一次,要加上提交动画
[UIView commitAnimations];
2、实现图片渐变成另一张图片的效果
先定义imagyer
@property(nonatomic,strong) CALayer *imageLayer;
实现并添加layer
self.imageLayer.frame = CGRectMake(40, 40, BILIW(350), BILIH(350));
[self.layer addSublayer:self.imageLayer];
设置图片渐变效果
CABasicAnimation *contentsAnimation = [CABasicAnimation animationWithKeyPath:@"contents"];
contentsAnimation.fromValue = self.imageLayer.contents;
contentsAnimation.toValue = (__bridgeid)(imageImg.CGImage);
contentsAnimation.duration = AnimationTime;
//设定layer动画结束之后的值,(必须设定,否则会恢复到动画之前的状态)
self.imageLayer.contents = (__bridgeid)(imageImg.CGImage);
//提交动画;
[self.imageLayer addAnimation:contentsAnimation forKey:nil];
3、实现对象沿轨迹运动动画效果
CAKeyframeAnimation创建动画原理,会复制一个新的对象来进行动画运动,但是对象原始的位置不会进行改变
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.removedOnCompletion = NO;//不删除复制的对象
pathAnimation.fillMode = kCAFillModeForwards;//停留在当前位置
pathAnimation.duration =AnimationTime;
// pathAnimation.repeatCount = 1;
//创建动画的运动轨迹
CGMutablePathRef curvedPath = CGPathCreateMutable();
//最后一个参数way控制旋转方向,yes,逆时针,no顺时针
CGPathAddArc(curvedPath, NULL, BILIW(250), BILIW(250), BILIW(175), startAngle, endAngle, way);
pathAnimation.path = curvedPath;
CGPathRelease(curvedPath);
[ringV.layer addAnimation:pathAnimation forKey:@"keyAnimation"];
以上是关于动画效果的主要内容,如果未能解决你的问题,请参考以下文章