Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mikezang

macrumors 6502a
Original poster
May 22, 2010
842
2
Tokyo, Japan
I am using code as below to rotate a UIView for 90 degrees, when I want to rotate 90 degrees again from last position and use the same code, nothing happened.
Code:
view.transform = CGAffineTransformMakeRotation(M_PI / 2);
But when I change to below, it rotate 90 degree from last position, I want to know why, I checked Programming Guide and Class Reference about UIView, CGContext and CGAffineTransform, but still not clear, hope you can answer my question.
Code:
view.transform = CGAffineTransformMakeRotation(M_PI);
 
Last edited:

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Setting the transform is not cumulative.

Code:
view.transform = CGAffineTransformMakeRotation(M_PI);

sets the transform M_PI

Code:
view.transform = CGAffineTransformMakeRotation(M_PI);
view.transform = CGAffineTransformMakeRotation(M_PI);

sets the transform to M_PI and then sets it to M_PI again. Which is clearly redundant.

It's just a property. It's never going to set it to 2*M_PI. Why would you expect it to work any differently?
 

mikezang

macrumors 6502a
Original poster
May 22, 2010
842
2
Tokyo, Japan
Sorry I made mistake, the first code os M_PI / 2, then is M_PI.

I use that code to animate my view, first view rotate 90 degrees in animation, so I think if I animated two times, view should rotate 180 degrees from original position, and rotate 90 degrees from position after first rotation!

But View only rotate 90 degrees even if I run same code more than two times, then I change code to M_PI after first rotation, this time view rotate more 90 degrees, now I got what I need.

The problem is why I have to set 180 degrees in second time, can you answer me?
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
I repeat: you are setting a property. When you set the rotation to 90º that's what happens. If you set it to 90º again it doesn't suddenly become 180º. You are not calling a command that rotates by an amount. You are setting it to a specific amount.

It's just as if you were setting an integer. If you set a property to 10 and then set it to 10 again you'd be really surprised and upset if the property value was 20.
 

mikezang

macrumors 6502a
Original poster
May 22, 2010
842
2
Tokyo, Japan
Well, I understood. thank you very much.

So can you tell me how I can let view rotate 90 in real, so that I can rotate 90 again let it in 180?

Maybe use CGContextRotateCTM?

I think CGAffineTransformRotate might be what I need, I will try after a few hours, as I have to sleep now, I am sit here since yesterday 1800.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.