Search code examples
ioscgaffinetransform

Image Scaling when using CGAffineTransformMakeScale


I have this UIImageview, with an image. It's a small image, that is tiled with the

resizableImageWithCapInsets

method. It's very useful to do screen size independent images, and it works well: if I programmatically change the frame size of the UIImageview, the image inside is not stretched, but repeated, so the pixels remain pixels.

Now, when I do a

self.myImageView.transform=CGAffineTransformMakeScale(5.0, 5.0);

to the UIImageview containing/displaying that image, I notice that the image now actually is stretched.

I tried reloading the image into the view, but that doesn't seem to help.

The UIImageView is in the "Scale to Fill" mode.

The question in short is: how do I make sure the image is not stretched, but tiled after the transformation?

UPDATE: the reason for using CGAffineTransformMakeScale is, that I want to grow/shrink the image(view) relative to its center.


Solution

  • Instead of applying the transform direct to the view, use CGRectApplyAffineTransform and transform the image view frame. This won't work well for all possible transformations though so limit to translation and scale.