Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does My Rotation only go Anti Clockwise when I want to go Clockwise?

[CATransaction begin];
            [CATransaction setAnimationDuration:5];
            CGAffineTransform currentTransform = squareLayer.affineTransform;
            CGFloat angle = M_PI;

            squareLayer.affineTransform = CGAffineTransformRotate(currentTransform, angle);
            [CATransaction commit];

and

[CATransaction begin];
            [CATransaction setAnimationDuration:5];
            CGAffineTransform currentTransform = squareLayer.affineTransform;
            CGFloat angle = (M_PI * -1);

            squareLayer.affineTransform = CGAffineTransformRotate(currentTransform, angle);
            [CATransaction commit];

I would have thought the -1 would have reversed the direction but apparently not?

like image 438
geminiCoder Avatar asked May 04 '12 09:05

geminiCoder


People also ask

Is counterclockwise and anti clockwise the same?

For counterclockwise (also referred to as anti-clockwise), the direction is in the opposite direction of the clockwise rotation. As adjectives, clockwise means moving in a rotary motion like a clock does while counterclockwise is moving in a rotary manner to the left side.

Does the earth move clockwise or anti clockwise?

Earth's rotation or Earth's spin is the rotation of planet Earth around its own axis, as well as changes in the orientation of the rotation axis in space. Earth rotates eastward, in prograde motion. As viewed from the northern polar star Polaris, Earth turns counterclockwise.

Why do motors rotate anticlockwise?

It is due to the counter clockwise motion of the motor. The motor rotates in the counter clockwise direction the blades of the fan are attached to the motor hence the blades rotates in the anti clockwise direction.

What is the difference between anti clockwise and clockwise?

Clockwise and anti-clockwise are ways of indicating the direction of a turn. So, what way is clockwise? Clockwise, involves a turn to the right as it follows the hands of a clock and anti-clockwise involves a turn to the left, against the direction of a clock's hands.


Video Answer


3 Answers

EDIT: Instead of -M_PI use -3 * M_PI, for anti-clockwise

and remove '-' sign for opposite direction.

like image 99
Harish Pathak Avatar answered Sep 28 '22 08:09

Harish Pathak


The angle is the same. To go full circle you need 2 * Pi, so half a circle is Pi. If you take -Pi it would end at the same point.

EDIT: If you need to make it turn clockwise you can go slightly off -Pi. Instead of -M_PI use -3.141593 for example.

like image 15
RadicalRaid Avatar answered Oct 23 '22 00:10

RadicalRaid


Just ran into this and while @radicalraid's solution works fine, I prefer adjusting the starting angle before rotation vs rotating to an angle less than the desired end point. Also, you can animate CALayer transforms using animation blocks.

My code:

// iOS will rotate the shortest distance to the end angle,
// using counter-clockwise if equal.
// Force the rotation to open clockwise and close counter-clockwise by bumping
// the initial angle
CGFloat startRadians, endRadians;
if (isOpening) {
    startRadians = 0.01f;
    endRadians = M_PI;

}
else {
    startRadians = M_PI - 0.01f;
    endRadians = 0.0f;
}

self.myImageView.layer.affineTransform = CGAffineTransformMakeRotation(startRadians);

[UIView animateWithDuration:0.3f
                 animations:^{
                     self.myImageView.layer.affineTransform = CGAffineTransformMakeRotation(endRadians);
                 }];
like image 9
XJones Avatar answered Oct 22 '22 22:10

XJones