Wingzero Wingzero - 11 months ago 66
iOS Question

rotate 180 degree for an UIImageView, and rotate back with same route

I got a button and want to rotate the image inside it:

self.DashButton.imageView.transform = CGAffineTransformMakeRotation(M_PI);

The image is a up-arrow to down-arrow after user click it
When clicking the button again, I want the down-arrow rotate to up-arrow again, but it is the same counterclockwise rotation, but I just want the arrow reverse back to up-arrow

rotate back code:

self.DashButton.imageView.transform = CGAffineTransformIdentity;

I tried

self.DashButton.imageView.transform = CGAffineTransformMakeRotation(-M_PI);

What I want is not rotate the full circle, just 180 rotate and -180 rotate, not a 360 full rotate


instead of -M_PI, use -3.14159. Kind of a trick, but below code saved my day.

self.DashButton.imageView.transform = CGAffineTransformMakeRotation(M_PI);
self.DashButton.imageView.transform = CGAffineTransformMakeRotation(M_PI - 3.14159);