(CABasicAnimation)基本动画
###基本动画相关属性
- fromValue:keyPath 相应属性的初始值
- byValue:keyPath相应属性的中间值
- toValue:keyPath相应属性的结束值
动画过程说明
- 随着动画的进行,在长度为duration的持续时间内,keyPath相应属性的值从fromValue渐渐地变为toValue;
- KeyPath内容是CALayer的可动Animatable画属性
- 如果fillMode=KCAFillModeForwards同时removedOnComletion=NO,那么在动画执行完毕后,图层会保持显示动画执行后的状态。但在实质上,图层的属性值还是动画执行前的初始值,并没有真正被改变。
##1、平移 2、缩放 3、旋转
- 平移

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
animation.toValue = @320;
animation.duration = 1;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = NO;
[self.view.layer addAnimation:animation forKey:@"animation"];
###缩放
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
animation.toValue = @2;
animation.duration = 0.25;
animation.repeatCount = 1;
animation.autoreverses = YES;
[self.view.layer addAnimation:animation forKey:@"animation"];
###旋转 *旋转
- (CAAnimation *)rotationAnimation {
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
animation.byValue = @( -2 * M_PI);//正数表示按照顺时针旋转,负数为逆时针方向旋转
animation.duration = 2.0;
animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = NO;
animation.autoreverses = YES;
animation.repeatCount = HUGE_VALF; // HUGE_VALF 最大浮点数,表示无限次重复
return animation;
}
来源:oschina
链接:https://my.oschina.net/u/2891871/blog/738784