关于CGAffineTransformMakeRotation旋转方向? [英] About CGAffineTransformMakeRotation rotation direction?

查看:544
本文介绍了关于CGAffineTransformMakeRotation旋转方向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用CGAffineTransformMakeRotation,我参考Apple文档,其中说


以弧度表示的角度,此矩阵旋转坐标系轴。 在iOS中,正值指定逆时针旋转,负值指定顺时针旋转。在OS X中,正值指定顺时针旋转,负值指定逆时针旋转。


因此,我传递参数90度,它应该逆时针旋转。

self.myView是灰色背景颜色视图,红色方块视图仅用于查看旋转方向

  #define DEGREES_TO_RADIANS(x)(x * M_PI / 180.0)
CGAffineTransform rotation = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(90));
[self.myView setTransform:rotation];






但为什么它顺时针旋转?

我正在尝试在模拟器和设备中使用两者都有相同的结果,顺时针旋转

然后使用动画:

  #define DEGREES_TO_RADIANS(x)(x * M_PI / 180.0)
CGAffineTransform rotation = CGAffineTransformMakeRotation (DEGREES_TO_RADIANS(90));
[UIView animateWithDuration:0.5
动画:^ {
self.myView.transform = rotation;
}
完成:^(BOOL完成){
NSLog(@%@,NSStringFromCGAffineTransform(self.myView.transform));
}];

它具有相同的结果,顺时针旋转。



有人可以解释原因,感谢您的回复。

解决方案

这是文档中的错误。



说相反。


I'm trying to use CGAffineTransformMakeRotation, and I refer Apple document which says

The angle, in radians, by which this matrix rotates the coordinate system axes. In iOS, a positive value specifies counterclockwise rotation and a negative value specifies clockwise rotation. In OS X, a positive value specifies clockwise rotation and a negative value specifies counterclockwise rotation.

So, I pass parameter 90 degree, it should counterclockwise rotation.
self.myView is gray background color view, and red square view is just for see rotation direction

#define DEGREES_TO_RADIANS(x) (x * M_PI/180.0)
CGAffineTransform rotation = CGAffineTransformMakeRotation( DEGREES_TO_RADIANS(90) );
[self.myView setTransform:rotation];


But why it clockwise rotation?
I'm trying use in simulator and device both have the same result, clockwise rotation
And then tring to use animation:

#define DEGREES_TO_RADIANS(x) (x * M_PI/180.0)
CGAffineTransform rotation = CGAffineTransformMakeRotation( DEGREES_TO_RADIANS(90) );
[UIView animateWithDuration:0.5
                 animations:^{
                     self.myView.transform = rotation;
                 }
                 completion:^(BOOL finished) {
                     NSLog(@"%@", NSStringFromCGAffineTransform(self.myView.transform));
                 }];

It has the same result, clockwise rotation.

Can somebody explain why, Thanks for the reply.

解决方案

This is an error in documentation.

Here they describe matrix and provide equations which they use to do the transform:

If you do the math, you'll see that for positive angles, it gives rotation counterclockwise when Y axis direction is upwards as in OS X and clockwise when Y axis directed downwards as in iOS

For example you may try to transform point (5,0) with 90 degrees, you will get (0,5), which means clockwise for iOS and counterclockwise for OS X.

The same piece of documentation still have the (false) part you quoted:

In iOS, a positive value specifies counterclockwise rotation and a negative value specifies clockwise rotation. In OS X, a positive value specifies clockwise rotation and a negative value specifies counterclockwise rotation.

Which is clearly wrong, because the equations (which are the part of the same document and are pretty standard rotation equations) say the opposite.

这篇关于关于CGAffineTransformMakeRotation旋转方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆