2011-01-23 9 views
5

के लिए मैं एक CAKeyframeAnimation कि एक CGPathAddEllipseInRect इस प्रकार का उपयोग कर एक चक्र के साथ एक UIView एनिमेट कर रहा हूँ। हालांकि, दृश्य मूल रूप से उस फ्रेम के बावजूद उसी स्थान पर शुरू होता प्रतीत होता है, जिस पर मूल रूप से स्थित है। क्या पथ पर दृश्य की प्रारंभिक स्थिति को समायोजित करने का कोई तरीका है?सेट प्रारंभ बिंदु CGAffineTransform

धन्यवाद!

CAKeyframeAnimation *myAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; 
myAnimation.fillMode = kCAFillModeForwards; 
myAnimation.repeatCount = 5; 
myAnimation.calculationMode = kCAAnimationPaced; 
myAnimation.duration = 10.0; 

CGMutablePathRef animationPath = CGPathCreateMutable(); 

CGPathAddEllipseInRect(animationPath, NULL, rect); 

myAnimation.path = animationPath; 
CGPathRelease(animationPath); 

[view.layer addAnimation:myAnimation forKey:@"changeViewLocation"]; 

उत्तर

1

मैं इसे CGPathAddEllipseInRect के लिए एक शुरुआत के बिंदु निर्धारित किया जा सकता है नहीं लगता है। CGPathAddEllipseInRect, आप का उपयोग करना चाहिए: CGPathAddArc

उपयोग करने के बजाय (कम से कम मैं सफल नहीं हुआ था)! उदाहरण के लिए:

CAKeyframeAnimation *myAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; 
myAnimation.fillMode = kCAFillModeForwards; 
myAnimation.repeatCount = 5; 
myAnimation.calculationMode = kCAAnimationPaced; 
myAnimation.duration = 10.0; 

CGMutablePathRef animationPath = CGPathCreateMutable(); 

NSInteger startVal = M_PI/2; 

//seventh value (end point) must be always 2*M_PI bigger for a full circle rotation 
CCGPathAddArc(animationPath, NULL, 100, 100, 100, startVal, startVal + 2*M_PI, NO); 

myAnimation.path = animationPath; 
CGPathRelease(animationPath); 

[view.layer addAnimation:myAnimation forKey:@"changeViewLocation"]; 

चक्र पूरा नीचे से शुरू बारी बारी से होगा - दक्षिणावर्त। रोटेशन प्रारंभ स्थिति बदलने के लिए startVal मान बदलें। (पूर्ण रोटेशन 2 * M_PI है)।

0

पिछला जवाब सही है और काम करता है, लेकिन वहाँ

CGFloat startVal = M_PI/2; 
बजाय

NSInteger startVal = M_PI/2; 
अन्यथा

, M_PI पूर्णांक बढ़ा दिया जाएगा होना चाहिए और आप सही कोण को प्राप्त करने में सक्षम नहीं होगा । पीएस पिछले जवाब पर टिप्पणी करने के लिए कम प्रतिष्ठा है, क्षमा करें।

संबंधित मुद्दे