Search code examples
iosswiftuiscrollviewswipe

Disable UIScrollView inertia (scrollViewDidEndDecelerating) Swift


Setup: I have a Scroll View that works great horizontally as well as a UISwipeGestureRecognizer that triggers a segue to another view when I swipe down.

Problem: If I am scrolling horizontally and I begin to swipe down (vertical scrolling disabled) WHILE the scrolling is decelerating, the swipe down action (segue) does not execute. It only works once the scrolling deceleration is complete.

enter image description here

Is there a way to disable the scroll deceleration (aka inertia) so that my swipe down gesture can be detected instantly? Perhaps there's a workaround to force UISwipeGestureRecognizer to be detected first?

Solutions in Swift are highly appreciated!


Solution

  • UIScrollView has a pinchGestureRecognizer and a panGestureRecognizer.If you have a UISwipeGestureRecognizer,the gesture will most likely be recognized as a UIPanGestureRecognizer.
    You can add a dependence to solve the problem:

    scrollView.panGestureRecognizer.requireGestureRecognizerToFail(swipeGesture)