I placed an imageView inside a scrollView for pinch zoom. This works, however I am not able to zoom a picture that is placed as an overlay on the base image to the same zoom factor.
func viewForZooming(in scrollView: UIScrollView) -> UIView? {
return baseImage
}
func scrollViewDidZoom(_ scrollView: UIScrollView) {
overlayImage.transform.scaledBy(x: scrollView.zoomScale, y: scrollView.zoomScale)
}
In the scrollView delegate, I am able to return only one ImageView, which works fine for the base image. I tried implementing the optional delegate scrollViewDidZoom and manually zoom the overlay image but it is not working. Is there another way to achieve this?
The usual thing is to have a single subview of the scroll view, the "content view". The user will not be aware of its existence; its job is to define the limits of scrolling (the content size) and to function as the zoomable view. Everything the user sees in the scroll view (your image view and overlay view) will be subviews of the content view, and will be scrolled and zoomed along with it.