2012-11-11 50 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

आप bezierPathWithOvalInRect के बजाय bezierPathWithArcCenter उपयोग कर सकते हैं, क्योंकि वह एक आरंभ और समाप्ति कोण निर्दिष्ट करने के लिए अनुमति देता है:

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