Search code examples
objective-cioscocoa-touchuiimageviewcgaffinetransform

UIImageView Resize and Rotate issue using Erica Sadun example - prepopulate location


I am using the example by Erica Sadun for how to resize and rotate a UIImageView: https://github.com/erica/iphone-3.0-cookbook-/tree/master/C08-Gestures/14-Resize%20And%20Rotate

It is a wonderful example and exactly what I am wanting, but it falls short in one area. I cannot figure out how to pre-populate the transform property of the UIImageView so that I can save the state of the image and load it back into a view later, with the same position, scale and rotation.

Currently every time I add the UIImageView subclass it starts in the top left corner of the screen, but for the life of me, I cannot figure out how to pre-populate the transform property so it doesn't so that.

When the image is created, we do:

originalSize = self.bounds.size;
originalTransform = CGAffineTransformIdentity;
touchBeginPoints = CFDictionaryCreateMutable(NULL, 0, NULL, NULL);// could this be the issue?

The subclass contains a lot of code, so I am not sure it should be reposted in its entirety.

Anyone used this before and could help?


Solution

  • CGAffineTransformIdentity is a blank transform and won't do anything.

    You need to set its transform to the transform you created.