CGAffineTransformIdentity not restarting UIImageView after multiple conversions?

I created a simple application with a segmented control at the top. When I click on one of the two segments of the control, the UIImageView starts to rotate. I have a reset button to set its conversion to CGAffineTransformIdentity.

The problem occurs when the method that performs the rotation animation of the view is called a second time by switching segments back and forth. Pressing reset deletes only the most recent animation. I need to disable segments a second time so that the animation stops with reset completely.

The following code gets called when I select a segment to rotate the UIImageView and is obviously called the second when I click between segments.

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

The reset button calls this code -

 self.imageView.transform = CGAffineTransformIdentity; 
+7
source share
1 answer

try it

 [UIView animateWithDuration:0.2 animations:^() { self.imageView.transform = CGAffineTransformIdentity; }]; 
+6
source

All Articles