Check direction of scroll in UIScrollView

前端 未结 3 1990
盖世英雄少女心
盖世英雄少女心 2020-12-17 03:46

I am trying to implement the method scrollViewWillBeginDragging. When this method is called I check that the user has selected one of the buttons that are w

3条回答
  •  盖世英雄少女心
    2020-12-17 04:32

    In scrollViewWillBeginDragging the scroll view has not yet moved (or registered the move) and so contentOffset will by 0. As of IOS 5 you can instead look in the scrollview's panGestureRecognizer to determine the direction and magnitude of the user's scrolling gesture.

    - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
    { 
        CGPoint translation = [scrollView.panGestureRecognizer translationInView:scrollView.superview];
    
        if(translation.x > 0)
        {
            // react to dragging right
        } else
        {
            // react to dragging left
        }
    }
    

提交回复
热议问题