Detect direction of UIScrollView scroll in scrollViewWillBeginDragging

后端 未结 9 1825
心在旅途
心在旅途 2020-12-17 09:30

I did google enough, & I did check posts like these ( Finding the direction of scrolling in a UIScrollView? ) in stackoverflow before posting this. I have a dynamic numb

9条回答
  •  死守一世寂寞
    2020-12-17 10:03

    scrollView.panGestureRecognizer translationInView:scrollView doesn't report anything useful in scrollViewWillBeginDragging in iOS 7.

    This does:

    In the @interface

    BOOL scrollDirectionDetermined;
    

    and:

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
        if (!scrollDirectionDetermined) {
            if ([scrollView.panGestureRecognizer translationInView:scrollView.superview].x > 0) {
                //scrolling rightwards
            } else {
                 //scrolling leftwards
           }
        scrollDirectionDetermined = YES;
        }
    }
    

    and:

    - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
        scrollDirectionDetermined = NO;
    }
    

提交回复
热议问题