2011-01-23 14 views
5

Estoy animando una UIView en un círculo utilizando una CAKeyframeAnimation que sigue a CGPathAddEllipseInRect. Sin embargo, la vista siempre parece comenzar en el mismo lugar, independientemente del marco en el que se encuentra originalmente. ¿Hay alguna forma de ajustar la posición de inicio de la vista en la ruta?Establecer punto de inicio para CGAffineTransform

Gracias!

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

Respuesta

1

No creo que sea posible establecer un punto de inicio para CGPathAddEllipseInRect. (Por lo menos no tuve éxito)

en lugar de utilizar: CGPathAddEllipseInRect, Deberá utilizar: CGPathAddArc! Por ejemplo:

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

girará círculo completo a partir de la parte inferior - en sentido horario. Cambie el valor de startVal para cambiar la posición de inicio de rotación. (la rotación completa es 2 * M_PI).

0

respuesta anterior es correcta y funciona, pero no debe haber

CGFloat startVal = M_PI/2; 

en lugar de

NSInteger startVal = M_PI/2; 

De lo contrario, M_PI será redondeado a un entero y usted no será capaz de alcanzar el ángulo exacto . P.S. tiene baja reputación para comentar la respuesta anterior, lo siento.

Cuestiones relacionadas