Xcode顺时针旋转uibutton
我想将 UIButton 顺时针旋转 180 度。但它总是逆时针旋转。
这就是我尝试的方法:
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);
我做错了什么?
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:UIViewAnimationCurveEaseInOut];
[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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有过类似的经历,我最好的猜测如下:
旋转变换转换为最终结果,意味着绝对旋转。由于旋转 -PI 和 +PI 会产生相同的最终效果(均为 180 度),因此动画最终始终选择默认方向;在 iOS 上似乎是逆时针方向。
通过将其设置为比 -M_PI 稍负的值,如 @kishorebjv 提到的,最短旋转路径是通过正方向(将动画切换为顺时针)。您可以使用 M_PI+0.01 或 M_PI-0.01 来查看此效果。两者都是正数,但它们的结果不同。
更详细的解释:
值:M_PI+0.01
方向: 逆时针
推理:这转化为 ~180.6 的旋转,
因此,最短旋转为负 179.4 度。
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.
我很惊讶......我不知道为什么会这样。
而不是 -M_PI 给出 -3.141593。
它会顺时针旋转..
到目前为止,它是一个快速修复。但可能不是您问题的确切答案
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