2011-07-27 11 views
7

He creado una aplicación simple con un control segmentado en la parte superior. Cuando hago clic en uno de los dos segmentos del control, UIImageView comienza a rotar. Tengo un botón de reinicio conectado para establecer su transformación a CGAffineTransformIdentity.CGAffineTransformIdentity no restablece un UIImageView después de múltiples transformaciones?

El problema ocurre cuando se llama al método que hace la animación de rotación de vista por segunda vez al cambiar los segmentos hacia adelante y hacia atrás. Al presionar Restablecer solo se elimina la animación más reciente. Tengo que cambiar segmentos por segunda vez para que las animaciones se detengan por completo.

Se llama al siguiente código cuando selecciono el segmento para rotar el UIImageView y obviamente llamo por segunda vez cuando hago clic entre los segmentos.

// Begin the animation block and set its name 
[UIView beginAnimations:@"Rotate Animation" context:nil]; 

// Set the duration of the animation in seconds (floating point value) 
[UIView setAnimationDuration:0.5]; 

// Set the number of times the animation will repeat (NSIntegerMax setting would repeat indefinately) (floating point value) 
[UIView setAnimationRepeatCount:NSIntegerMax]; 

// Set the animation to auto-reverse (complete the animation in one direction and then do it backwards) 
[UIView setAnimationRepeatAutoreverses:YES]; 

// Animation curve dictates the speed over time of an animation (UIViewAnimationCurveEaseIn, UIViewAnimationCurveEaseOut, UIViewAnimationCurveEaseInOut, UIViewAnimationCurveLinear) 
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 

// Changes the imageViews transform property to rotate the view using CGAffineTransformRotate 
// CGAffineTransformRotate(transformToStartFrom, angleToRotateInRadians) 
// Starting transform property can be set to CGAffineTransformIdentity to start from views original transform state 
// This can also be done using CGAffineTransformMakeRotation(angleInRadians) to start from the IdentityTransform without implicitly stating so 
self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, degreesToRadians(90)); 

[UIView commitAnimations]; 

el botón de reinicio llamadas de este código -

self.imageView.transform = CGAffineTransformIdentity; 

Respuesta

6

probar esto

[UIView animateWithDuration:0.2 animations:^() { 

    self.imageView.transform = CGAffineTransformIdentity; 



}]; 
+2

duración de la animación Will (0,2 segundos), añadir el efecto deseado? Por favor, explique un poco más ... – HDdeveloper

+0

En su lugar, puede establecer el valor que desee, simplemente le indiqué que tenía la opción de duración. Cheers :) –

+0

Las preguntas dicen que ya está configurando CGAffineTransformIdentity y no funciona – trapper

Cuestiones relacionadas