Search code examples
iosuiimageviewcgaffinetransformuipinchgesturerecognizer

UIImageView scaling?


I have two questions relating to UIImageViews and the pinch gesture:

  1. I looked at the documentation for layer.anchorPoint and it says that this is the point at which all transformations are based, and it is located at the center of a view (UIImageView in my case), so why is my image scaling from the top right corner and how can I fix it?

  2. I also would like this image to be scaled inversely, so when fingers pinch it is scaled up and when fingers spread apart, it is scaled down. how could I do this?

I tried using CGAffineTransformInverse but this is being super glitchy, not sure if it should be but it is.

Thanks in advance!


Solution

  • After hours of research I have found an unlikely answer to my first question and it is incredibly simple.

    First, my problem was being caused by the auto layout feature, apparently if you don't add any constraints it will pin your view using the top and left side of the frame this is what causes it to scale from the top left corner. so to get rid of this, for reasons I am totally oblivious to, all that is required is to add this statement to your viewDidLoad.

    [view setTranslatesAutoLayoutConstraints: YES];

    if anyone can explain why this works please let me know in a comment!