Is there a way to know when the animation has end and uiscrollview has come to rest.
-
Regarding this very old question, nowadays there are THREE situations which must be covered. It's one of the strangest and most difficult issues in iOS. :/ – Fattie Jan 31 '20 at 15:03
5 Answers

- 2,610
- 3
- 27
- 31
-
1It doesn't get called everytime ex. when scrollRectToVisible() is called inside traitCollationDidChange – Michał Ziobro Oct 04 '18 at 17:40
-
1
-
I agree with @Fattie's comment because there are multiple scenarios which scrolling can end. This answer is not as good as Fattie's answer below. – Michael Sep 07 '22 at 08:16
-
@Fattie Yes, and for some reason SO bot decides to remove 1 reputation from me. Anyway, just wanted to thank you for your answer. – Michael Sep 07 '22 at 16:37
I do it like this because sometimes using the delegate isn't practical for me, like if i'm doing it in UIViewController transition:
[UIView animateWithDuration:0.3 animations:^{
[scrollView setContentOffset:CGPointMake(0, -scrollView.contentInset.top) animated:NO];
} completion:^(BOOL finished) {
// This is called when it's complete
}];

- 26,576
- 13
- 94
- 112
-
Exactly! I also used the same code only then it worked as per expectation. – Developer Jul 28 '16 at 05:48
-
I put my cell modification code into the `completion` but my `animation` and `completion` are executing line by line. not working as expected :( – Bindiya Feb 14 '18 at 13:57
-
Implement UIScrollViewDelegate delegate methods for your UIScrollView the following way:
Use scrollViewDidEndScrollingAnimation:
to detect when the scrolling animation concludes when you've initiated the scrolling by calling setContentOffset:animated:
or scrollRectToVisible:animated:
methods (with animated:YES).
If you want to monitor scroll view motion that's been initiated by touch gestures, use scrollViewDidEndDecelerating:
method, which is called when the scrolling movement comes to a halt.

- 7,997
- 6
- 47
- 60
-
for anyone googling here, this very old answer is now **incorrect** - thanks, Apple! :/ – Fattie Feb 02 '20 at 18:07
You need to cover THREE (!) cases. Thanks, Apple.
// do note that you need all three of the following
public func scrollViewDidEndScrollingAnimation(_ s: UIScrollView) {
// covers case setContentOffset/scrollRectToVisible
fingerOrProgrammaticMoveDone()
}
public func scrollViewDidEndDragging(_ s: UIScrollView, willDecelerate d: Bool) {
if decelerate == false {
// covers certain cases of user finger
fingerOrProgrammaticMoveDone()
}
}
public func scrollViewDidEndDecelerating(_ s: UIScrollView) {
// covers certain cases of user finger
fingerOrProgrammaticMoveDone()
}
(Be careful to not forget the extra "if" clause in the middle one.)
Then in fingerOrProgrammaticMoveDone()
, do what you need.
A good example of this is the nightmare of handling paged scrolling. It is very, very hared to know what page you are on.
scrollViewDidEndDecelerating:
UIScrollView delegate method is called when scrollView stops completely.

- 8,090
- 3
- 23
- 21