[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?
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.
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.
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.
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.
EDIT: Instead of -M_PI use -3 * M_PI, for anti-clockwise
and remove '-' sign for opposite direction.
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.
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);
}];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With