Cri*_*tiC 8 xcode rotation uibutton ios4
我想顺时针旋转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];
Run Code Online (Sandbox Code Playgroud)
这个:
myButton.transform = CGAffineTransformRotate( myButton.transform, - M_PI);
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
小智 16
我有类似的经历,我最好的猜测如下:
旋转变换转换为净结果,意味着绝对旋转.由于旋转-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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5195 次 |
| 最近记录: |