Search code examples
iosobjective-cuiscrollviewdelegatesuiscrollviewdelegate

UIScrollView events for scrolling that definitely occurred


I am working with aUIScrollview, and based on if the user scrolls left or right, I reconfigure the UI. The problem is that I need to verify that the user definitely crossed from one screen to another (something along contentOffset).

I've tried using this method:

  -(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;

But this will fire if the user kind of moves the scrollview partially in one direction, but then doesn't complete the gesture.

I've also tried this method:

   -(void)scrollViewDidScroll:(UIScrollView *)scrollView;

but mainly the same issue; the scrollview scrolls left and right, but on an iPhone, with a content with of 640 ( 320 * 2). I am trying to figure out if the scroll did cross over or not, from one location to the other.

Any suggestions?


Solution

  • I found a way of doing this :

    I have a variable to maintain the x location of the contentOffset

     -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
       currX = self.scrollView.contentOffset.x;
     }
    

    And then in this event :

    -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
       if(self.scrollView.contentOffset.x == currX ) {
          return;//This is what I needed, If I haven't panned to another view return
       }
     //Here I do my thing.