I'm trying to make simple twists and turns in Objective-C, and there are a couple of problems right away. One thing is the mismatch that I get from CGAffineTransformRotate, and how the M_PI is incompatible when used inside this function.
Suppose I do this and attach to a button. When I click it once, it rotates 180 degrees counterclockwise (well and the documentation follows), but when I click it again, it rotates 180 degrees clockwise, even if the value is not negative. Changing M_PI to -M_PI does the same without any difference in rotation:
[UIView animateWithDuration:secs delay:0.0 options:option animations:^{ self.transform = CGAffineTransformRotate(self.transform, M_PI);
Now suppose I changed the M_PI to 3.141593, that is, the value that the M_PI contains when I print it. Now when I press the button, it works perfectly fine. Both times, it will rotate 180 degrees counterclockwise. When I change it to -3.141593, it will also work perfectly fine clockwise:
self.transform = CGAffineTransformRotate(self.transform, 3.141593);
When I play with it more, the behavior becomes weirder.
Suppose I want to rotate 90 degrees (pi / 2). M_PI now has the same behavior as using a value, but the rotation is the opposite of what it should be:
//Should be Clockwise but rotates CounterClockwise self.transform = CGAffineTransformRotate(self.transform, -M_PI/2); self.transform = CGAffineTransformRotate(self.transform, -1.5707965); //Should be CounterClockwise but rotates Clockwise self.transform = CGAffineTransformRotate(self.transform, M_PI/2); self.transform = CGAffineTransformRotate(self.transform, 1.5707965);
And if I want to rotate something more than 180 degrees (PI), then I just rotate the shortest route, even if I indicate a positive or negative rotation. When I rotate 360 โโdegrees (2PI), it doesn't even rotate.
Why is this happening, and what can I do to make it more consistent? And the second question I have is how can I rotate things 270 and 360 degrees.