1

I would like to return the original image size after I use pinch gesture to zoom in or out.

What I have found the similar answer is

How to get original image when we zoom in and zoom out the image in ios,

it uses scrollView. Not exactly what I need.

Here is my code, It's a gesture response sent by #selector

func respondToGesture(_ gesture: UIGestureRecognizer) -> Void {

    if let pinch = gesture as? UIPinchGestureRecognizer {

        if let img = pinch.view as? UIImageView {

           img.transform = CGAffineTransform(scaleX: pinch.scale, y: pinch.scale)

           if pinch.state == .ended
           {
               img.transform = CGAffineTransform(scaleX: (1 / pinch.scale), y: (1 / pinch.scale))
           }
        }
    }
}

Hope to get some suggestions!! Thanks~

HungCLo
  • 442
  • 2
  • 6
  • 21

1 Answers1

3

Use this to reset the size of your image

yourImage.transform = CGAffineTransform.identity

Hope this helps!

Mohamad Bachir Sidani
  • 2,077
  • 1
  • 11
  • 17
  • Thanks, I also find a alternative solution. The transform scale default is 1, just set CGAffineTransform(scaleX: 1, y: 1) to my imageView. – HungCLo Aug 22 '17 at 06:54