0
我有以下specifed的軌道和行星的演示代碼: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];
我可以旋轉這個軌道上,以模擬地球的_orbitLayer.affineTransform = CGAffineTransformMakeRotation(startAngle);
circyling但我不能動畫_orbitLayer.affineTransform
。我的動畫代碼不起作用。它出什麼問題了?
試試這個'CABasicAnimation * arcAnimation = [CABasicAnimation animationWithKeyPath
arcAnimation.toValue = [NSNumber numberWithFloat:endAngle];
和
CABasicAnimation *arcAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
保存:@「改造。迴轉」]; ' – 2015-03-19 05:11:40
不工作,即使'affineTransform' – Wingzero 2015-03-19 05:14:55
不,我試過這三個,沒有人工作 – Wingzero 2015-03-19 05:19:23