Nils Ziehn Nils Ziehn - 9 months ago 76
iOS Question

UiScrollview scrollviewDidScroll detect user touch

I am using a

in my app, and use the
method to move some other views that are not inside the scrollview. This behavior should only occur when the user is actually moving the scrollview with a finger and not when the touch event ends.

Currently I am using the
property of the scrollview to get this behavior, but it has a problem: when the user swipes over the scrollview and touches it again before it stopped decelerating, the
property is not true although the user is dragging the scrollview with a finger.

Answer Source

The UIScrollView has a panGestureRecogniser property, which tracks the pan gestures in the scroll view. You can track the state of the pan gesture in the scrollViewDidScroll to know exactly what state the panning is in.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

    if ([scrollView isEqual:yourScrollView]) {

        switch (scrollView.panGestureRecognizer.state) {

            case UIGestureRecognizerStateBegan:

                // User began dragging

            case UIGestureRecognizerStateChanged:

                // User is currently dragging the scroll view

            case UIGestureRecognizerStatePossible:

                // The scroll view scrolling but the user is no longer touching the scrollview (table is decelerating)