1

I need to detect the user scroll direction to prevent wrong swipe. I use this following code

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{

        CGPoint velocity = [(UIPanGestureRecognizer *)gestureRecognizer velocityInView:self];


            if (fabs(velocity.y) * 2 < fabs(velocity.x))
            {
                //scroll LEFT or RIGHT 
                return NO;
            }
            else
            {
                //scroll UP or DOWN 
            }


         return YES;
}

it works in most case, except if the user scroll while the scrollview is decelerating, then the velocity factor is null, and i can't calculate the scroll direction.

EDIT 1

similar problem : link

Community
  • 1
  • 1
Julie Bsd
  • 191
  • 1
  • 2
  • 10
  • set the contentsize to width of screen and it won't scroll to left to right – Ahmad Ishfaq May 18 '16 at 19:50
  • 1
    i use a vertical collectionView inside an horizontal pageViewController. When the user scroll up/down the collectionView, i need to prevent ambigus left/right swipe. it works except when the collectionView is decelerating. – Julie Bsd May 18 '16 at 20:05

1 Answers1

1

I think the simplest solution will be to detect the scroll direction directly on the UIScrollViewDelegate. Have a look at this answer

Community
  • 1
  • 1
Julien Quere
  • 2,407
  • 16
  • 21
  • i need to know the direction inside the `- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer` method to block any wrong gestures – Julie Bsd May 19 '16 at 16:46