Question

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?

Était-ce utile?

La solution 2

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.

Autres conseils

I am not entirely sure what you mean by "crossed from one screen to another" I assume you mean paging? If so, here's what you can do:

- (void)scrollViewDidEndDecelerating:(UIScrollView *)sender {
    int page = sender.contentOffset.x / width;
    [self.pageControl setCurrentPage:page]; // in case you need it for updating a UIPageControl
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top