Search code examples
objective-cxcodeiosuiscrollview

UIScrollView direction from scrollViewWillBeginDecelerating


Is it possible to retrieve the direction that a UIScrollView is scrolling to, in the method;

-(void) scrollViewWillBeginDecelerating:(UIScrollView *)scrollView

If so, how can this be achieved?


Solution

  • you could try something like this:

    - (void)scrollViewDidScroll:(UIScrollView *)sender 
    {
      xCoord = scrollview.contentOffset.x;
    }
    
    -(void) scrollViewWillBeginDecelerating:(UIScrollView *)sender 
    {
    
       if (xCoord > scrollView.contentOffset.x) {
         //RIGHT
       } else if (xCoord < scrollView.contentOffset.x) {
         //LEFT
       }
    
    }
    

    store the x coord of the scrollViews contentOffset when it begins scrolling, then compare it in scrollViewWillBeginDecelerating