1

I've a strange issue.Where I have a ScrollView and ContentOffset was already Set to it. And I've made a Condition in its Delegate by the below Code.

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

    if(scrollOffsetY > 90 && scrollOffsetY < 150) {

     NSLog(@"ContentOffset===>%f",ContentOffset);

    }
}

The Condition Which I've Written Works and Get into it only When I Scroll the scrollview Slowly. If I Scroll Faster. It Doesn't Getting into my Loop.

How Do I fix this ? and Get the Exact Value when the Condition is True ?

Vicky_Vignesh
  • 584
  • 2
  • 14
  • move your code to enddeclrating – Anbu.Karthik Apr 20 '17 at 12:57
  • scrollViewDidScroll only updates for every frame. If you scroll fast the contentOffset can jump by very large number for every frame. So it can jump from below 90 to above 150 in one frame and the code will never get hit. Without knowing what your goal is there no way to advice a way to 'fix' this. – Jon Rose Apr 20 '17 at 13:07
  • Hi @Anbu.Karthik, scrollViewDidEndDecelerating Delegate only calls after the scrolling is finished, so when I scroll Fast . The Condition satisfy only when the Scroll Stop Between the Value of the Content offset in the If Condition which I've mentioned. So this doesn't Help me. – Vicky_Vignesh Apr 20 '17 at 13:13
  • Hi @JonRose, Yah you said It right. But How can I Achieve this Condition ? Is there any Alternative way For this to Achieve ? – Vicky_Vignesh Apr 20 '17 at 13:16
  • what is your goal? – Jon Rose Apr 20 '17 at 13:18
  • @JonRose My goal is to make a calculation ` CGFloat imageX = (scrollOffsetY - 90) * (axisXDuration / 60); ` Within the Condition. This calculation Helps me to make an Animation. – Vicky_Vignesh Apr 20 '17 at 13:24

1 Answers1

1

UIScrollView doesn't call delegate for every scrolled pixel. Instead it calls it on every frameshot will be displayed. When you scroll quickly, the scroll view may skip the area you want to check. If you need to catch the moment when the specified area if on the screen you may add a variable to store the previous offset and add a condition like this:

 if (previousScrollOffsetY > 150 && scrollOffsetY < 90) || (previousScrollOffsetY < 90 && scrollOffsetY > 150) {
    NSLog(@"Skipped area")
}
previousScrollOffsetY = scrollOffsetY;
Alex
  • 1,155
  • 1
  • 8
  • 12