I have a collectionView. I want to detect scroll direction. I have a two different animation style for scroll down and scroll up. So I must learn scroll direction.
CGPoint scrollVelocity = [self.collectionView.panGestureRecognizer
velocityInView:self.collectionView.superview];
if (scrollVelocity.y > 0.0f)
NSLog(@"scroll up");
else if(scrollVelocity.y < 0.0f)
NSLog(@"scroll down");
This is just work at finger touched. Not work for me
this is the best way to get scroll direction, hope this helps you
Swift 4.2
I was trying to find a way to detect if the user is mostly trying to pull vertically or horizontally the scrollView. I give you my solution, I hope it can be useful to anyone :
This work find for me and I use this to avoid the scrollView to move horizontally when scrolling vertically and opposite.
Try this:
Add this somewhere in you header:
Then override the
scrollViewDidScroll:
method:Found in Finding the direction of scrolling in a UIScrollView?