Question

I have a UIImageView that is an image of the star. The problem is I want the star to rotate when I move it. How can I rotate a UIImageView to make it look like it is spinning for 3 seconds. I want it to spin 720 degrees.

Was it helpful?

Solution

For a very simple approach, you can use

imageView.transform = CGAffineTransformMakeRotation(radianRotation);

where radianRotation is a float, e.g. 4*pi for 720 degrees. You can play with basic animations and changing the rotation however you like.

However, if you want a more sophisticated solution, then I highly recommend you look at the answers to this related post: how to rotate UIIMageVIew with fix point?

Also, see the myriad related posts linked on the right hand side of your screen. Many have all the code you need (barring going around in a circle twice).

OTHER TIPS

You can also use

[imageView layer].transform = CATransform3DMakeRotation(variables);

For your commodity, additionally to PengOne's answer you can use M_PI, M_PI_2, M_PI_4 constants that are available in math.h.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top