Double Tap Zoom to The Tap Location Swift 5 iOS 13


Hello, I find a problem where user wants to zoom to the tap location in ImageView. Actually ImageView inside UIScrollview. Because it's not just zoom when double tap but user can zoom manually with pinning. So basically it's like gallery album in iPhone, you can see it.

When I try find the way on the internet, it doesn't work like the way I want. Double tap to zoom working but it just zoom on the center not to the tap location. You need to combine UIScrollview with UIImageview to use gesture zoom. Because UIImageview itself doesn't use scrollview so it will not effect scrollview.

Maybe in iOS version before 13 the way on the internet it works. Because I see some posting get upvote and every comment say it works. But in new version of iOS we need to check again. So it's like swift version language. It has developed better again.

So I finally combine answer on the internet to make what I want. So  this is the code




As you can see, I make if condition to catch event double tap. There is an answer that works but you need to combine with other answer to do zooming out. Because it just works with zooming in. The value when zooming out all the way is one ( 1 ). So I can check it with if condition then I give zooming out code to zoom out. And now the code works like a charm.

I don't give you the detail of my class. Because it jsut uses UIScrollview and UIImageview. You can do it at your own.

I'll give you the source, If you need to know deeper about the solution discussion.

source : https://stackoverflow.com/questions/3967971/how-to-zoom-in-out-photo-on-double-tap-in-the-iphone-wwdc-2010-104-photoscroll/33838414#33838414

https://stackoverflow.com/questions/10759872/how-to-get-the-image-to-zoom-where-i-double-tapped/40527171#40527171

Popular posts from this blog

How to restart the app with flutter Android and iOS

How to have ConstraintLayout inside ScrollView and ScrollView inside ConstraintLayout Android

Missing system image Android Studio solution