0

我使用 CAShapeLayer 创建了一个圆圈。我想在固定中心旋转这个圆圈。我正在使用以下代码进行动画。使用此代码圈正在旋转,但不在固定中心。中心是否在不断变化。我不希望这种情况发生。

这是我的动画代码

CABasicAnimation* rotationAnimation;
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 * rotations * 2.0 ];
    rotationAnimation.duration = 10.0; //    rotationAnimation.cumulative = YES;
    rotationAnimation.repeatCount = 1.0; 
    rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];

    [circle1 addAnimation:rotationAnimation forKey:@"rotationAnimation"];

谢谢

4

1 回答 1

0

这将使它保持在矩形内。

[circle1 setAnchorPoint:(0.5,0.5)]; 

CGFloat angle = rotationAnimation.toValue;
CGFloat radius = someRadius;
CGPoint rotationCenter = CGPointMake(centerX,centerY); 
circle1.frame = CGRectMake(rotationCenter.x + radius * cos(angle),  rotationCenter.y + radius * sin(angle), circle1.frame.size.width, circle1.frame.size.height);
于 2013-03-05T11:18:39.400 回答