2011-01-23 14 views
5

CGPathAddEllipseInRectに続くCAKeyframeAnimationを使用して円に沿って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が整数に丸められます、あなたが正確な角度を達成することはできませんがなければなりません。 P.P.以前の答えをコメントする評判が低い、申し訳ありません。

関連する問題