Search code examples
uiviewcore-graphicscgaffinetransformaffinetransform

Using only part of CGAffineTransformIdentity


Is there any way to only use certain aspects of the transform identity when I'm resetting something to its CGAffineTransformIdentity?

I have this method that resets my image view:

- (void)resetImage
{
    [UIView beginAnimations:nil context:nil];
    [firstImageView setTransform:CGAffineTransformIdentity];
    [UIView commitAnimations];
}

But I now want to make a new method that centers the image but leaves everything else about the transform i.e.(scale, rotation).

Is this something I can do simply so I can use an animation block like in my resetImage method? Or do I need to go a far more complicated route?

Thanks in advance!

just as a warning, I have very little experience with CG so take it easy on me :)


Solution

  • The identity transformation has no aspects. You're not saying “subtract all the things I did to it before” (such that you could exclude some of those things from the subtraction); you are resetting it to its initial, non-transformative value.

    But I now want to make a new method that centers the image but leaves everything else about the transform i.e.(scale, rotation).

    I assume you mean “leaves everything else … out”.

    Then you need to make a transformation that contains the translation(s), but not the scale or rotation.