I'm doing a page view controller with a photo album, and since I haven't been able to find a way to pan the image zoomed without changing the picture, I want the image to return to its original size when the user stops pinching.
This is my code:
@objc func pinch(sender:UIPinchGestureRecognizer) {
if sender.state == .began || sender.state == .changed {
let currentScale = self.contentImageView.frame.size.width / self.contentImageView.bounds.size.width
let newScale = currentScale*sender.scale
let transform = CGAffineTransform(scaleX: newScale, y: newScale)
self.contentImageView.transform = transform
sender.scale = 1
if sender.state == .ended {
contentImageView.transform = CGAffineTransform.identity
}
}
}
The zooming part works fine, but when I release the pinch it doesn't do anything, any suggestions would be very appreciated.