0

I have a UIView within a UIScrollView. I want the view to do something when a tap on it begins, and do something different when the tap ends. Therefor I used a UILongPressGestureRecognizer. I set the minimumPressDuration to zero. This works fine, but my problem is that I can't use the scroll view properly anymore because every touch within the view now fires the gesture recognizer.

Has anyone an idea how to solve this? Can I tell the LongPressGestureRecognizer not to react on swipe gestures?

Nishant Bhindi
  • 2,242
  • 8
  • 21

1 Answers1

3

Have you tried setting:

let gesture = UILongPressGestureRecognizer()
gesture.cancelsTouchesInView = false

Also try using a UILongPressGestureRecogniser with:

extension ViewController: UIGestureRecognizerDelegate {
    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
        return true
    }
}

Where ViewController is the delegate of your gesture recogniser.

Pranav Kasetti
  • 8,770
  • 2
  • 50
  • 71