10

I am trying to implement something based on the UIScrollView delegates, scrollViewDidScroll: in particular. So I read the scrollView.contentOffset in the delegate method and it works great until I start scrolling faster, then the contentOffset just skips up to 50 points in Y coordinate:

enter image description here

Does anyone know how to get a better precision of contentOffset?

7
  • 1
    use for better precision scrollViewDidEndScrollingAnimation.
    – Om Prakash
    Sep 3, 2015 at 6:55
  • But scrollViewDidEndScrollingAnimation: is called once the animation is concluded: Tells the delegate when a scrolling animation in the scroll view concludes. The scroll view calls this method at the end of its implementations of the setContentOffset:animated: and scrollRectToVisible:animated: methods, but only if animations are requested. Sep 3, 2015 at 16:00
  • Please inform me if you get a solution for the same. I am facing the same issue.
    – GoGreen
    Dec 16, 2015 at 3:49
  • Do you have any solution? I am facing the same issue. If you have answer, please inform me, thanks Sep 12, 2018 at 16:19
  • My guess is that if the user scrolls fast enough, there will always be jumps. I don't think it makes sense for UIKit to update the value of contentOffset more often than once per animation frame (1/60 of a second). Perhaps you could log the timestamp at which the delegate method is called and see the time interval (not distance) at which each call happens. Oct 10, 2018 at 8:17

1 Answer 1

-1

KVO will provide a message on every change, but the work you do in the observation method should be done quickly, so as to not induce lag...

To begin observing:

// assuming you have a scroll view outlet property
[self.scrollView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil];

To observe changes:

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
    if (object == self.scrollView) {
        NSLog(@"%f", self.scrollView.contentOffset.y);
    }
}

To stop observing:

[self.scrollView removeObserver:self forKeyPath:@"contentOffset"];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.