I’m a beginner to the iOS development, and I’m trying to display an image (a map in fact) which need to be zoomable and pannable. My problem is that I don’t know how to add an overlay which will follow the pan to always represent the same location, but won’t be scaled by the zoom. There will be several overlays, and each one must be clickable.
To zoom and pan the image (map), I added my UIImageView in a UIScrollView and it works great, but I have no idea how to add this feature.
I found this thread but it is not really the same problem since his overlay is static :
UIScrollview with two images – Keeping 1 image zoomable and 1 image static (fixed size)
I’ve developped the same application in android, and to make this work I was converting a pixel of the map in screen coordinates thanks to the transformation matrix, and I overrode the onDraw method to display it, but I don’t know how to do the same on iOS, and I don’t know if this is the better solution.
Thanks for any help.
Ok so I found a way to do it, if it can helps anybody :
I added my overlay in the scrollView, with the background image (the map).
In order to zoom, the custom scrollview need a delegate with the following methods :
With this, we are saying that the zoom only occurs on the background image, but as the overlay is in the
UIScrollView, it pans with it. So the only thing we need to care is to move the Overlay when the zoom change, and we know it with thescrollViewDidZoommethod.To handle the touch events, we override the
touchEnded:withEvent:ofCustomScrollViewand we forward it to the overlay if there is only one tap. I don’t show theOverlayImageViewsince it only override this same method (toucheEnded:withEvent:) to handle a touch on it.Hope this will help.