2015-03-19 2 views
0

У меня есть ниже кода, как предписанный в технических заданиях орбиты и планета демо:CABasicAnimation с CALayer.affineTransform не работает

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

я мог повернуть эту орбиту, чтобы имитировать планету circyling по _orbitLayer.affineTransform = CGAffineTransformMakeRotation(startAngle); Но я не могу оживить _orbitLayer.affineTransform. Мой код анимации не работает. Что с этим не так?

+0

попробовать это 'CABasicAnimation * arcAnimation = [CABasicAnimation animationWithKeyPath: @" преобразования. вращение "]; ' –

+0

не работает, даже если' affineTransform' – Wingzero

+0

Нет, я пробовал эти три, никто не работает – Wingzero

ответ

2

Интересно, что использовать

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]; 
Смежные вопросы