Rotating CAShapeLayer moves the position too

前端 未结 2 1199
慢半拍i
慢半拍i 2021-01-04 13:24

I am creating a CAShapeLayer. I am adding rotation animation to it. Somehow transformation result is weird. The child layer is moving along with rotation. I need it to be in

2条回答
  •  滥情空心
    2021-01-04 14:18

    It works right. Just enable frame for your layer:

    circleLayer.borderWidth = 1;
    circleLayer.borderColor = [UIColor redColor].CGColor;
    

    And you see that frame rotating right. Also better to use byValue here:

    CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    animation.byValue = @(2 * M_PI);
    animation.duration = 10.0f;
    animation.repeatCount = INFINITY;
    animation.removedOnCompletion = NO;
    [circleLayer addAnimation:animation forKey:@"SpinAnimation"];
    

    So your problem is a geometry of shape.

提交回复
热议问题