2012-11-11 26 views
6

Tôi đang làm động việc vẽ hình tròn cơ bản. Điều này hoạt động tốt, ngoại trừ hoạt hình bắt đầu vẽ ở vị trí 3 giờ. Có ai biết làm thế nào tôi có thể làm cho nó bắt đầu lúc 12 giờ?CABasicAnimation - Đặt vị trí đột quỵ bắt đầu

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"]; 

Trả lời

13

Bạn có thể sử dụng bezierPathWithArcCenter thay vì bezierPathWithOvalInRect, bởi vì đó cho phép xác định một sự khởi đầu và kết thúc góc:

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; 

Xem tài liệu bezierPathWithArcCenter cho ý nghĩa của các góc.

+0

Tôi đã gặp vấn đề tương tự và nó hoạt động tuyệt vời! – carantes

Các vấn đề liên quan