2013-03-05 89 views
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"]; 

感谢

+1

[circle1 setAnchorPoint:(0.5,0.5)];这将保持它在里面。 – BhushanVU 2013-03-05 11:13:03

回答

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); 
+0

仍然有同样的问题 – user1926201 2013-03-05 11:31:22

+0

我已经做了编辑检查... – BhushanVU 2013-03-05 11:43:00