正反箭头旋转动画

 参考: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;

    //Z180度旋转后复制一个图层

    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"];

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值