Is there a way to know when the animation has end and uiscrollview has come to rest.
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
}];
completion
but my animation
and completion
are executing line by line. not working as expected :( –
Ogg 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.
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.
© 2022 - 2024 — McMap. All rights reserved.