Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is an older question, but the other solutions did not work well for me, so I came up with another solution:</p> <p>Rotating an image is essentially just a normal rotation with a translation applied, ensuring that the point you want to rotate around is still in the same spot after the rotation. To do this, calculate the position's CGPoint in your image before the rotation, get the position after the rotation, and apply the difference as a translation on the image, "snapping" it into the right position. Here is the code that I've been using:</p> <p>Keep in mind that the translation should be applied via CGAffineTransform, not moving the .center, because the translation will need to be relative to the rotation, and CGAffineTransformTranslate() takes care of that.</p> <pre><code>// Note: self is the superview of _imageView // Get the rotation point CGPoint rotationPointInSelf = self.center; // or whatever point you want to rotate around CGPoint rotationPointInImage = [_imageView convertPoint:rotationPointInSelf fromView:self]; // Rotate the image _imageView.transform = CGAffineTransformRotate(_imageView.transform, angle); // Get the new location of the rotation point CGPoint newRotationPointInImage = [_imageView convertPoint:rotationPointInSelf fromView:self]; // Calculate the difference between the point's old position and its new one CGPoint translation = CGPointMake(rotationPointInImage.x - newRotationPointInImage.x, rotationPointInImage.y - newRotationPointInImage.y); // Move the image so the point is back in it's old location _imageView.transform = CGAffineTransformTranslate(_imageView.transform, -translation.x, -translation.y); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload