1

I have a scroll view with 2 subviews: the first one is an image view and the second one (on top of the first one) is a UIView, where the user can draw the content he wants to.

I have implemented the scroll view delegate method viewForZoomingInScrollView(scrollView: UIScrollView), so I am able to zoom in and out both subviews at the same time as I want to.

In order to do that, I created an additional view ("contView" in the code below) that contains both the subviews mentioned before and added it as a subview of the scroll view. This view is the one returned by the delegate method
viewForZoomingInScrollView(scrollView: UIScrollView).

Here you can find the code:

import UIKit

class ViewController: UIViewController {

    //The view where users can draw what they want
    @IBOutlet weak var drawingView: DrawningView!

    //The imageView behind the "drawingView"
    @IBOutlet weak var imageView: UIImageView!

    //The view that contains "imageView" and "drawingView" 
    @IBOutlet weak var contView: UIView!
    @IBOutlet weak var scrollView: UIScrollView!

    override func viewDidLoad() {
        super.viewDidLoad()

        scrollView.minimumZoomScale = 1.0
        scrollView.maximumZoomScale = 5.0
        scrollView.contentSize = CGSize(width: view.bounds.width, height: view.bounds.height)
    }
}

extension ViewController: UIScrollViewDelegate {

    func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView? {
        return contView
    }
}

This is my problem: when zooming out, the "contView" doesn't allow me to draw any content on the "drawingView" anymore.

Probably because the view returned by the delegate method is still active even if the zooming process stopped.

Do I have to implement something in the "scrollViewDidEndZooming()" delegate method, to be able to draw what I want on the "drawingView" again?

Please can someone point me in the right direction with suggestions or examples to solve my problem?

Pang
  • 9,564
  • 146
  • 81
  • 122

0 Answers0