2012-11-11 180 views
6

我正在爲基本圓圈的繪製設置動畫。這工作正常,除了動畫開始繪製在3點鐘的位置。有誰知道我可以如何讓它在12點開始?CABasicAnimation - 設置開始筆劃位置

self.circle = [CAShapeLayer layer]; 
self.circle.fillColor = nil; 
self.circle.lineWidth = 7; 
self.circle.strokeColor = [UIColor blackColor].CGColor; 
self.circle.bounds = CGRectMake(0, 0, 200, 200); 
self.circle.path = [UIBezierPath bezierPathWithOvalInRect:self.circle.bounds].CGPath; 
[self.view.layer addSublayer:self.circle]; 

CABasicAnimation *drawAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; 
drawAnimation.duration   = 5.0; 
drawAnimation.repeatCount   = 1.0; 
drawAnimation.removedOnCompletion = NO; 
drawAnimation.fromValue = [NSNumber numberWithFloat:0.0f]; 
drawAnimation.toValue = [NSNumber numberWithFloat:1.0f]; 
drawAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]; 
[self.circle addAnimation:drawAnimation forKey:@"drawCircleAnimation"]; 

回答

13

可以使用bezierPathWithArcCenter代替bezierPathWithOvalInRect,因爲它允許指定一個開始和結束角度:

CGFloat radius = self.circle.bounds.size.width/2; // Assuming that width == height 
self.circle.path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(radius, radius) 
                radius:radius 
               startAngle:(-M_PI/2) 
               endAngle:(3*M_PI/2) 
               clockwise:YES].CGPath; 

bezierPathWithArcCenter文檔角度的意義。

+0

我有同樣的問題,它效果很好! – carantes