XCode顺时针旋转uibutton

我想顺时针旋转180度的UIButton.但它总是逆时针旋转.

这是我尝试的方式:

CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.3];

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

[UIView commitAnimations];

这个:

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

我做错了什么?

解决方法

我有类似的经历,我最好的猜测如下:

旋转变换转换为净结果,意味着绝对旋转.由于旋转-PI和PI产生相同的净效果(均为180度),动画最终总是选择认方向;这在iOS上似乎逆时针.

通过将其设置为比-M_PI稍微更负的值,如@kishorebjv所述,最短的旋转路径是通过正方向(将动画切换为顺时针方向).您可以使用M_PI 0.01或M_PI-0.01来查看此效果.两者都是正数,但它们导致不同的方向.

更冗长的解释:
值:M_PI 0.01
方向:逆时针
推理:这可以转换为~180.6的旋转,
因此,最短的旋转为负179.4度.

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

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...