Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to judge the direction of the UIScrollView is going to scroll?

Note:My question is the direction of the scrollView will scroll,not scrolling.That is to say,when user scroll the scrollView,can we get the direction of the scrollView is going to scroll before the scrollView begin scrolling?

Any idea?Thanks in advance.

like image 892
无夜之星辰 Avatar asked Jun 16 '17 06:06

无夜之星辰


1 Answers

By using scroll view delegate you can identify.

Objective C :

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView {
    CGPoint point = [scrollView.panGestureRecognizer translationInView:scrollView.superview];
    if (point.y > 0) {
        // Dragging down
    } else {
        // Dragging up
    }
}

Swift :

 func scrollViewWillBeginDecelerating(_ scrollView: UIScrollView) {
        let actualPosition = scrollView.panGestureRecognizer.translation(in: scrollView.superview)
        if (actualPosition.y > 0){
            // Dragging down
        }else{
            // Dragging up
        }
    }
like image 136
Subramanian P Avatar answered Nov 06 '22 14:11

Subramanian P