按照路径移动
CAKeyframeAnimation* ani = [CAKeyframeAnimation animation];
ani.keyPath = @"position";
UIBezierPath *path =[UIBezierPath bezierPathWithArcCenter:_img.center radius:100 startAngle:0 endAngle:M_PI*2 clockwise:YES];
ani.path = path.CGPath;
ani.repeatCount = MAXFLOAT;
ani.duration = 2;
ani.removedOnCompletion = NO;
ani.fillMode = kCAFillModeBoth;
抖动
#define angle2Radion(angle) (angle / 180.0 * M_PI)
CAKeyframeAnimation*ani2 = [CAKeyframeAnimation animation];
ani2.keyPath = @"transform.rotation";
ani2.values = @[@(angle2Radion(-5)),@(angle2Radion(5)),@(angle2Radion(-5))];
ani2.duration = 0.15;
ani2.repeatCount = MAXFLOAT;
缩放动画
注意:缩放动画想要中心点不变,未知应该有position确定,而不是path
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(0, 0) radius:40 startAngle:0 endAngle:M_PI * 2 clockwise:NO];
_targetLayer = [CAShapeLayer layer];
_targetLayer.lineDashPattern = @[@4.0, @2.0];
_targetLayer.lineWidth = 1;
_targetLayer.strokeColor = [UIColor blueColor].CGColor;
_targetLayer.fillColor = [UIColor colorWithRed:0 green:0 blue:1 alpha:0.1].CGColor;
_targetLayer.path = path.CGPath;
_targetLayer.position = CGPointMake(60, 330);
[self.view.layer addSublayer:_targetLayer];
--- animation -------
// 创建不断改变CALayer的transform属性的属性动画
CAKeyframeAnimation* scale = [CAKeyframeAnimation
animationWithKeyPath:@"transform.scale"];
scale.values = @[@1 ,@1.2, @1.0,@0.8,@1.0];
scale.duration = 1;
scale.repeatCount = MAXFLOAT;
scale.removedOnCompletion = NO;
[self.targetLayer addAnimation:scale forKey:@"scale"];