CALayer.affineTransform 的 CABasicAnimation 不工作

CABasicAnimation with CALayer.affineTransform not working

我将以下代码指定为轨道和行星演示:

    _orbitLayer.bounds = CGRectMake(0, 0, radius*2, radius*2);
    _orbitLayer.position = center;
    _orbitLayer.cornerRadius = radius;
    _orbitLayer.borderColor = [UIColor redColor].CGColor;
    _orbitLayer.borderWidth = 1.5;
    if ([_orbitLayer superlayer]) {
        [_orbitLayer removeAllAnimations];
        [_orbitLayer removeFromSuperlayer];
    }
    [self.layer insertSublayer:_orbitLayer above:_stripeLayer];

    // planet circyle
    _dotCircyleLayer.bounds = CGRectMake(0, 0, (arcWidth - 10),(arcWidth - 10));
    CGPoint anchor_center = CGPointMake(_orbitLayer.bounds.size.width,
                                        _orbitLayer.bounds.size.height/2);
    _dotCircyleLayer.position = anchor_center;
    _dotCircyleLayer.cornerRadius = (arcWidth - 10)/2;
    _dotCircyleLayer.backgroundColor = anchorColor.CGColor;
    if ([_dotCircyleLayer superlayer])
        [_dotCircyleLayer removeFromSuperlayer];
    [_orbitLayer addSublayer:_dotCircyleLayer];
    _orbitLayer.affineTransform = CGAffineTransformMakeRotation(startAngle);

// animation
    CABasicAnimation *arcAnimation = [CABasicAnimation animationWithKeyPath:@"affineTransform"];
    arcAnimation.duration = 0.8;
    arcAnimation.fromValue = [NSValue valueWithCGAffineTransform:CGAffineTransformMakeRotation(startAngle)];
    arcAnimation.toValue = [NSValue valueWithCGAffineTransform:CGAffineTransformMakeRotation(endAngle)];
    arcAnimation.removedOnCompletion = NO;
    [_orbitLayer addAnimation:arcAnimation forKey:nil];

我可以旋转这个轨道来模拟行星自转 _orbitLayer.affineTransform = CGAffineTransformMakeRotation(startAngle); 但我无法制作动画 _orbitLayer.affineTransform。我的动画代码不起作用。怎么了?

有趣的是,使用

arcAnimation.toValue = [NSNumber numberWithFloat:endAngle];

CABasicAnimation *arcAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];

拯救了我的一天

_orbitLayer.affineTransform = CGAffineTransformMakeRotation(startAngle);
CABasicAnimation *arcAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
arcAnimation.duration = 0.8;
//    arcAnimation.fromValue = [NSValue valueWithCGAffineTransform:CGAffineTransformMakeRotation(startAngle)];
//    arcAnimation.toValue = [NSValue valueWithCGAffineTransform:CGAffineTransformMakeRotation(endAngle)];
    arcAnimation.fromValue = [NSNumber numberWithFloat:startAngle];
    arcAnimation.toValue = [NSNumber numberWithFloat:endAngle];
    arcAnimation.removedOnCompletion = NO;
    [_orbitLayer addAnimation:arcAnimation forKey:nil];