How to rotate UIImageView gradually?

I need to rotate the image several times 90 degrees. I am using the following code,

CGAffineTransform transform = CGAffineTransformMakeRotation(PI/2);
shape.transform = transform;

      

here the form is my UIImageview.

The problem is that every time I press the rotate button it rotates it from its original position, which I don't want. I would rotate it from a new position.

I am new to programming on iphone, sorry if I am missing something very basic and thanks in advance for the help.

Kedar

+2


source to share


1 answer


If you are trying to animate this rotation, you can read my answer to this question where someone tried to animate the incremental rotation of the view. It turns out that incremental transform animation using CABasicAnimations is a little more complex than you'd expect. First, you need to read the current transformation of your UIView layer from its presentation layer, and then pass it to your animation as fromValue.

However, in your case it appears that you are using a UIView animation block to animate the transform property of your view. The code you wrote will only support setting your image's transformation to the same 90 degree rotation, which will not progressively rotate the view 90 degrees. To do an incremental rotation, I believe you need something like the following:



CGAffineTransform transform = CGAffineTransformRotate(shape.transform, M_PI / 2.0f);
shape.transform = transform;

      

which will grab the current view transformation, rotate it 90 degrees and then apply the transformation to the view. Again, this can lead to the same problems as CABasicAnimations, in which case you should refer to the above answer.

+7


source







All Articles