参考:http://www.jianshu.com/p/272aa1f26c62
——————————关键代码——————————————
rotateView = [UIView new];
//影响赋值的图层距离
rotateView.frame = CGRectMake(0, 0, 200, 200);
rotateView.center = self.view.center;
[self.view addSubview:rotateView];
CAReplicatorLayer *layer = [CAReplicatorLayer new];
layer.frame = rotateView.bounds;
[rotateView.layer addSublayer:layer];
//弧线路径
CGPoint center = CGPointMake(rotateView.frame.size.width / 2, rotateView.frame.size.width / 2);
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center
radius:30
startAngle:0
endAngle:DEGREES_TO_RADIANS(120)
clockwise:YES];
path.lineCapStyle = kCGLineCapRound;
path.lineJoinStyle = kCGLineJoinRound;
path.lineWidth = 2.0;
//正方向箭头路径
UIBezierPath *_startArrowPath1 = [UIBezierPath bezierPath];
[_startArrowPath1 moveToPoint:CGPointMake(106, 63)];
[_startArrowPath1 addLineToPoint:CGPointMake(116, 73)];
[_startArrowPath1 addLineToPoint:CGPointMake(106, 83)];
_startArrowPath1.lineCapStyle = kCGLineCapButt;
_startArrowPath1.lineWidth = 2.0;
//反方向箭路径
UIBezierPath *_endArrowPath1 = [UIBezierPath bezierPath];
[_endArrowPath1 moveToPoint:CGPointMake(126, 63)];
[_endArrowPath1 addLineToPoint:CGPointMake(116, 73)];
[_endArrowPath1 addLineToPoint:CGPointMake(126, 83)];
_endArrowPath1.lineCapStyle = kCGLineCapButt;
_endArrowPath1.lineWidth = 2.0;
//箭头
CAShapeLayer *lineLayer = [CAShapeLayer new];
lineLayer.path = _startArrowPath1.CGPath;
lineLayer.fillColor = [UIColor clearColor].CGColor;
lineLayer.strokeColor = [UIColor blackColor].CGColor;
lineLayer.borderWidth = 2;
lineLayer.lineCap = kCALineCapButt;
[layer addSublayer:lineLayer];
//弧线
CAShapeLayer *rotateLayer= [CAShapeLayer new];
rotateLayer.path = path.CGPath;
rotateLayer.fillColor = [UIColor clearColor].CGColor;
rotateLayer.strokeColor = [UIColor blackColor].CGColor;
rotateLayer.borderWidth = 2;
rotateLayer.lineCap = kCALineCapRound;
rotateLayer.lineJoin = kCALineJoinRound;
[layer addSublayer:rotateLayer];
//复制图层数:2
layer.instanceCount = 2;
//绕Z轴180度旋转后复制一个图层
layer.instanceTransform = CATransform3DMakeRotation(M_PI, 0, 0, 1);
//正反箭头变化的动画
CAKeyframeAnimation *aniChangePath1 = [CAKeyframeAnimation animationWithKeyPath:@"path"];
aniChangePath1.values = @[(__bridge id)_startArrowPath1.CGPath,(__bridge id)_endArrowPath1.CGPath,(__bridge id)_endArrowPath1.CGPath];
aniChangePath1.keyTimes = @[@(0.45),@.75,@.95];
aniChangePath1.autoreverses = YES;
aniChangePath1.repeatCount = NSIntegerMax;
aniChangePath1.duration = 1;
[lineLayer addAnimation:aniChangePath1 forKey:@"path"];
//旋转动画
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
theAnimation.duration=3;
theAnimation.repeatCount = NSIntegerMax;
theAnimation.fromValue = [NSNumber numberWithFloat:0];
theAnimation.toValue = [NSNumber numberWithFloat:3.1415926];
[rotateView.layer addAnimation:theAnimation forKey:@"animateTransform"];