UIBezierPath *bezierPath1 = [UIBezierPath bezierPath];
[bezierPath1 moveToPoint: CGPointMake(286.5, 611.5)]; //一定要设置 不然底层的CGPathRef找不到起始点,将会崩溃
[bezierPath1 addCurveToPoint: CGPointMake(322.5, 545.5) controlPoint1: CGPointMake(286.5, 606.5) controlPoint2: CGPointMake(347.5, 601.5)];
[bezierPath1 addCurveToPoint: CGPointMake(336.5, 460.5) controlPoint1: CGPointMake(297.5, 489.5) controlPoint2: CGPointMake(350.5, 511.5)];
[bezierPath1 addCurveToPoint: CGPointMake(353.5, 399.5) controlPoint1: CGPointMake(322.5, 409.5) controlPoint2: CGPointMake(340.5, 421.5)];
[bezierPath1 addCurveToPoint: CGPointMake(322.5, 337.5) controlPoint1: CGPointMake(366.5, 377.5) controlPoint2: CGPointMake(322.5, 337.5)];
[bezierPath1 addCurveToPoint: CGPointMake(286.5, 292.5) controlPoint1: CGPointMake(322.5, 337.5) controlPoint2: CGPointMake(267.5, 333.5)];
[bezierPath1 addCurveToPoint: CGPointMake(273.5, 234.5) controlPoint1: CGPointMake(305.5, 251.5) controlPoint2: CGPointMake(273.5, 234.5)];
//位置动画
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
animation.path = [bezierPath1 CGPath]; //设置animation的path
//可以单独设置某个动画的时间
animation.duration = 15.0f;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
//透明度动画
CABasicAnimation * alphAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
alphAnimation.fromValue = @(fromOpacity_);
alphAnimation.toValue = @(toOpacity_);
//大小动画
CABasicAnimation *resizeAnimation = [CABasicAnimation animationWithKeyPath:@"bounds.size"];
[resizeAnimation setToValue:[NSValue valueWithCGSize:CGSizeMake(40, 40)]];
resizeAnimation.fillMode = kCAFillModeForwards;
resizeAnimation.removedOnCompletion = NO;
resizeAnimation.duration = 0.6;
//旋转动画
CABasicAnimation *transformAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
transformAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
transformAnimation.fromValue = @(0);
transformAnimation.toValue = @(M_PI_4 * (arc4random()%80 + 30));
//创建动画组
CAAnimationGroup *animationGroup = [[CAAnimationGroup alloc]init];
animationGroup.duration = arc4random()%4 + 2;
animationGroup.animations = @[animation, alphAnimation,resizeAnimation,transformAnimation];
//_demoView为一个UIImageView
[_demoView.layer addAnimation:animationGroup forKey:nil];