No need to add an extra variable to keep track of this. Just use the UIScrollView
's panGestureRecognizer
property like this. Unfortunately, this works only if the velocity isn't 0:
CGFloat yVelocity = [scrollView.panGestureRecognizer velocityInView:scrollView].y;
if (yVelocity < 0) {
NSLog(@"Up");
} else if (yVelocity > 0) {
NSLog(@"Down");
} else {
NSLog(@"Can't determine direction as velocity is 0");
}
You can use a combination of x and y components to detect up, down, left and right.