5

I would like to know how to use the UIScrollViewDelegate to detect when the scroll view stops moving suddenly because the user has touched and held the screen after momentum has been initiated from a fast pan.

The scrollViewDidEndDecelerating: method only fires for the above case when the user has lifted their finger. However, if the user taps and holds during scroll view momentum then this method doesn't fire (until they lift their finger). Is there anyways to intercept this when the scroll view stops dead upon the user's touch down?

Barjavel
  • 1,626
  • 3
  • 19
  • 31

3 Answers3

4

Have you tried using scrollViewWillBeginDragging? Alternatively (since the docs indicate that scrollViewWillBeginDragging may not fire immediately) you can try using scrollViewDidScroll and checking if the user is currently touching the scrollview...

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if(scrollView.isTracking){
        //do something
    }
}
mjisrawi
  • 7,846
  • 3
  • 24
  • 27
2

Well, you could have a flag that is raised when the user starts scrolling, which ends in scrollViewDidEndDecelerating. That way, if the user starts scrolling again before the flag is cleared, you will know that they touched it during a deceleration.

borrrden
  • 33,256
  • 8
  • 74
  • 109
0

You don't have to implement your own.

Our friend Apple already provides you the way to detect the situation.

if needed for more, reference guide here : https://developer.apple.com/documentation/uikit/uiscrollviewdelegate/1619436-scrollviewdidenddragging

func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
    if decelerate {
      print("true if scrolling stops, keeping touch on the screen!")
    } else {
      print("false if scrolling stops, detaching touch on the screen")
    }
}
boraseoksoon
  • 2,164
  • 1
  • 20
  • 25