Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
442 views
in Technique[技术] by (71.8m points)

ios - About CGAffineTransformMakeRotation rotation direction?

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];

Before Rotation After 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is an error in documentation.

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

enter image description here

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...