How can I reliably rotate an image around a point?
A rotation is always done around (0,0).
To translate around a point you FIRST need to translate the rotate point to (0,0) and then rotate it, and then translate it back.
So it should be:
// cx, cy is center of screen
// move (cx,cy) to (0,0)
CGAffineTransform transform = CGAffineTransformMakeTranslation(-cx, -cy);
// roate around (0,0)
transform = CGAffineTransformRotate(transform, angleRadians);
// mov e (0,0) back to (cx,cy)
transform = CGAffineTransformTranslate(transform,cx,cy);
This line:
CGAffineTransform transform = CGAffineTransformMakeTranslation(x, y);
moves the image by x, y.
(Note-- you will spin around the control point, whatever you've set that to be)
this line:
transform = CGAffineTransformRotate(transform, a);
rotates it around the control point.
If your control point is in the top left hand corner (the default), it will spin around the top lefthand corner.
You need to set this:
[self layer].anchorPoint = CGPointMake(0.5, 0.5);
to get it to spin around the center of the layer.