Issues with UIScrollView and touchesBegan

Viewed 28

When a user touches one of the white UIViews, it runs its touchesBegan:

...

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        delegate.startedTouchingPage(page: self)
        ...

The delegate is the VC. startedTouchingPage is implemented in the VC as

    func startedTouchingPage(page: Page) {
        if (page.tool == .PEN || page.tool == .ERASER) {
            scrollView.isScrollEnabled = false
            scrollView.panGestureRecognizer.isEnabled = false
        }
    }

I thought this would prevent scrolling and panning, and allow the pen to draw in peace. But instead, when I try to draw on the page, the pen sometimes draws properly, and sometimes instead scrolls the page.

It turns out that the times that the page scrolls instead of draws, touchesBegan didn't run, and thus startedTouchingPage didnt run either. I can't figure out why...

0 Answers
Related