开发者

Xcode rotate uibutton clockwise

I want to rotate an UIButton at 180 degrees clockwise. But it always rotate counterclockwise.

This is how I tried:

CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIVie开发者_StackOverflow中文版wAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.3];

myButton.transform = CGAffineTransformRotate( myButton.transform, M_PI);

[UIView commitAnimations];

also this:

myButton.transform = CGAffineTransformRotate( myButton.transform, - M_PI);

What am I doing wrong?


I've had a similar experience, and my best guess is the following:

The rotation transform translates to a net result, meaning an absolute rotation. Since rotating -PI and +PI results in the same net effect (both 180 degrees), the animation ends up always choosing the default direction; which seems to be counterclockwise on iOS.

By setting it to a value slightly more negative than -M_PI, as @kishorebjv mentioned, the shortest rotation path is through the positive direction (switching the animation to clockwise). You can see this effect by using M_PI+0.01 or M_PI-0.01. Both are positive numbers, but they result in different directions.

More verbose explanation: Value: M_PI+0.01 Direction: Counterclockwise Reasoning: This is this translates to a rotation of ~180.6, which the shortest rotation is thus a negative 179.4 degrees.

Value: M_PI-0.01
Direction: Clockwise
Reasoning: This is this translates to a rotation of ~179.4, 
which the shortest rotation is thus a positive 179.4 degrees.

And going back to the value given by kishorebjv
Value: -3.141593
Direction: Clockwise
Reasoning: The value is slightly past -180 degrees, recalling PI is 3.1415926
....so the shortest rotation is a positive 179 degrees


I'm surprised..I don't know why its happening like that.

Instead of -M_PI give -3.141593.

It 'll rotate clockwise..

as of now its a quick fix.but probably not a exact answer for your question

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜