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