首页 > 系统 > iOS > 正文

iOS 常用动画

2019-11-09 16:48:50
字体:
来源:转载
供稿:网友

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

这里写图片描述

共同学习,共同进步!


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表