1.CABasicAnimation
// 1.创建核心动画
CABasicAnimation *anima =[CABasicAnimation animation];
// 1.1告诉系统要执行什么样的动画
anima.keyPath = @"position";
//设置通过动画将layer从哪
// anima.fromValue =[NSValue valueWithCGPoint:CGPointMake(0,0)];
//到哪(到指定的位置)
anima.toValue =[NSValue valueWithCGPoint:CGPointMake(200,300)];
// 在当前位置的基础上增加多少
// anima.byValue =[NSValue valueWithCGPoint:CGPointMake(0,300)];
//设置动画时间
anima.duration = 1;
// 1.2设置动画执行完毕之后不删除动画
anima.removedOnCompletion = NO;
// 1.3设置保存动画的最新状态
anima.fillMode = kCAFillModeForwards;
// 2.添加核心动画到Layer
[self.myLayer addAnimation:anima forKey:nil];
2.CAKeyframeAnimation
// 1.创建核心动画
CAKeyframeAnimation *keyAnima =[CAKeyframeAnimation animation];
keyAnima.keyPath = @"transform.rotation";
//度数/ 180 * M_PI
keyAnima.values = @[@(-angle2Radian(4)),@(angle2Radian(4)),@(-angle2Radian(4))];
keyAnima.removedOnCompletion = NO;
keyAnima.fillMode = kCAFillModeForwards;
keyAnima.duration = 0.1;
//设置动画重复的次数
keyAnima.repeatCount = MAXFLOAT;
// 2.添加核心动画
[self.iconView.layer addAnimation:keyAnima forKey:nil];
3.CATransition
// 1.创建核心动画
CATransition *ca =[CATransition animation];
// 1.1动画过渡类型
ca.type = @"cube";
// 1.2动画过渡方向
ca.subtype = kCATransitionFromRight;
// 1.3动画起点(在整体动画的百分比)
// ca.startProgress = 0.5;
ca.endProgress = 0.5;
//动画时间
ca.duration = 1;
// 2.添加核心动画
[self.iconView.layer addAnimation:ca forKey:nil];
//组动画
4. CAAnimationGroup *groupAnima =[CAAnimationGroup animation];
groupAnima.animations = @[a1,a2,a3];
groupAnima.duration = 2;
groupAnima.fillMode = kCAFillModeForwards;
groupAnima.removedOnCompletion = NO;
groupAnima.delegate = self;
[self.iconView.layer addAnimation:groupAnima forKey:nil];
5.UIView动画
网友评论