2013-03-05 88 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