Search code examples
iosobjective-cuiviewrotationcgaffinetransform

How can I rotate an image 360 degrees TWICE?


Basic Animation:

[UIView animateWithDuration:7.75
                 animations:^{

                     self.transform = CGAffineTransformRotate(CGAffineTransformIdentity, -M_PI);
                 }
                 completion:^(BOOL finished){

                     [UIView animateWithDuration:7.75
                                      animations:^{

                                          self.transform = CGAffineTransformRotate(CGAffineTransformIdentity, -M_PI);
                                      }
                                      completion:^(BOOL finished){

                                      }];
                 }];

I'd like to rotate the image by 360 degrees and then rotate it again by 360 degrees but for some reason it doesn't execute the second rotation.

Why? What could possibly go wrong?


Solution

  • The "problem" is that when we get to the second animation, you are trying to set the view's transform to CGAffineTransformRotate(CGAffineTransformIdentity, -M_PI) — but the view's transform is already CGAffineTransformRotate(CGAffineTransformIdentity, -M_PI), because that's what you set it to in the first animation! Thus, nothing happens because you are not asking to make any kind of change; you cannot animate a value to itself.