2
votes

I want to detect when the user lifts their finger in a UITableView while they scroll, so in the UIScrollView delegate method scrollViewDidScroll:

func scrollViewDidScroll(scrollView: UIScrollView)
{
    // Some code…


    if scrollView.panGestureRecognizer.state == .Ended
    {
        NSLog("ENDED")
    }
}

To me this sounds like it should work, so when I investigated further and logged what states happen at this point, the only two logs were Changed and Possible.

To my understanding Ended should happen before possible if the gesture has ended.

Apple docs:

The gesture recognizer has received touches recognized as the end of a continuous gesture. It sends its action message (or messages) at the next cycle of the run loop and resets its state to UIGestureRecognizerStatePossible.

What exactly is going on here? And how do I find when the user lifts their finger off my UITableView during a scroll?

2

2 Answers

3
votes

Okay, so scrollViewDidEndDragging:willDecelerate: doesn’t fire when the scroll view isn’t being dragged, it’s actually when the user lifts their finger. This is where Ended is fired.

1
votes

You can determine when a finger is lifted by implementing the -scrollViewDidEndDragging:willDecelerate: UIScrollViewDelegate method. No need to inspect the state of the underlying gesture recognizer.