I animate the scroll with scrollRectToVisible:animated:
But scrollViewDidEndDecelerating
is not getting called.
Is there a way to force the function to be called?
scrollViewDidEndDecelerating
won't be called for scrollRectToVisible
or setContentOffset
(i.e, scrolling programmatically). If you notice the declaration of this method in the header file it clearly mentions that it's "called on finger up as we are moving".
Now, to address your issue, scrollViewDidEndScrollingAnimation
delegate will be called (for setContentOffset
and scrollRectToVisible
), which you can use.
As you've found, scrollViewDidEndDecelerating
isn't always called (if you moved a scroll view with your finger and brought it to a stop it wouldn't get called either).
Since scrollViewDidEndDecelerating
is a delegate method you can force it to be called like this:
[[scrollView delegate] scrollViewDidEndDecelerating:scrollView];
I solved it by calling scrollViewDidEndDecelerating from scrollViewDidEndScrollingAnimation
-(void) scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
{
[self scrollViewDidEndDecelerating:scrollView];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
//your code
}
Adding the code below fixed an issue in my case.
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
if !decelerate {
scrollViewDidEndDecelerating(scrollView)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With