-
-
Save fl034/fda2e8140e9999df60166595d322ae13 to your computer and use it in GitHub Desktop.
Double Tap Zoom to The Tap Location Swift 5 iOS 13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@objc func handleDoubleTap(_ recognizer: UITapGestureRecognizer) { | |
let scale = min(scrollView.zoomScale * 2, scrollView.maximumZoomScale) | |
if scrollView.zoomScale == scrollView.minimumZoomScale { // zoom in | |
let point = recognizer.location(in: imageView) | |
let scrollSize = scrollView.frame.size | |
let zoomScale = scrollView.maximumZoomScale * 0.7 | |
let size = CGSize(width: scrollSize.width / zoomScale, | |
height: scrollSize.height / zoomScale) | |
let origin = CGPoint(x: point.x - size.width / 2, | |
y: point.y - size.height / 2) | |
scrollView.zoom(to:CGRect(origin: origin, size: size), animated: true) | |
} else { // zoom out | |
scrollView.setZoomScale(scrollView.minimumZoomScale, animated: true) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! It helps me a lot!