0

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?

Vulkan
  • 1,004
  • 16
  • 44
  • 1
    -M_PI is the same as 180 degrees, not 360... And setting the transform twice to the same value will of course not animate the second "change", because it aint one. Why would you want to rotate in two separate ways anyway? Basically you will however not be able to do it with UIView animation blocks, you have to use CABasicAnimations. – luk2302 Jul 27 '15 at 18:16
  • @matt we apparently did, it looks like I went to the right one ;) – luk2302 Jul 27 '15 at 18:22
  • I should have gone to that one! - But I do actually see the problem; using 2*M_PI is unreliable. Anyway, this question has been hashed out numerous times; I've linked to a duplicate with a lot of approaches. – matt Jul 27 '15 at 18:23
  • Also, the OP should see my answer here: http://stackoverflow.com/a/21772533/341994 – matt Jul 27 '15 at 18:23

1 Answers1

2

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.

matt
  • 515,959
  • 87
  • 875
  • 1,141