iOS 常用动画

来源:互联网 发布:ip地址和域名 编辑:程序博客网 时间:2024/05/19 00:14

CABasicAnimation基础动画

例如:

 UIView *rotationViewX = [[UIView alloc]initWithFrame:CGRectMake(20, 100, 70, 70)];    rotationViewX.backgroundColor = VIEW_COLOR;    [self.view addSubview:rotationViewX];    CABasicAnimation *rotationAnimationX = [CABasicAnimation animationWithKeyPath:@"transform.rotation.x"];    rotationAnimationX.beginTime = 0.0;    rotationAnimationX.toValue = @(2*M_PI);    rotationAnimationX.duration = 1.5;    rotationAnimationX.repeatCount = HUGE_VALF;    [rotationViewX.layer addAnimation:rotationAnimationX forKey:@"rotationAnimationX"];

基础动画常用的keypath:
这里写图片描述
设定动画的属性和说明:
这里写图片描述

CAKeyframeAnimation基础动画

CAKeyframeAnimation *orbitAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"];    orbitAnim.duration = 5;    orbitAnim.path = path.CGPath;    orbitAnim.calculationMode = kCAAnimationPaced;    orbitAnim.fillMode = kCAFillModeForwards;    orbitAnim.repeatCount = HUGE_VALF;    orbitAnim.rotationMode = kCAAnimationRotateAutoReverse;    [animView.layer addAnimation:orbitAnim forKey:@"orbitAnim"];

画线动画、线条递增、递减动画

 CABasicAnimation *pathAnim = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];    pathAnim.duration = 5.0;    pathAnim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];    pathAnim.fromValue = @(0);    pathAnim.toValue = @(1);    pathAnim.autoreverses = YES;    pathAnim.fillMode = kCAFillModeForwards;    pathAnim.repeatCount = HUGE_VALF;    [shapeLayer addAnimation:pathAnim forKey:@"strokeEndAnim"];

另还有弹性动画,波浪效果,火苗效果,详见demo:
https://github.com/ZJQian/AnimationDemo/tree/master

这里写图片描述

共同学习,共同进步!

0 0