Reputation: 345
Is there a way to check if my tableview just finished scrolling? table.isDragging
and table.isDecelerating
are the only two methods that I can find. I am not sure how I can either anticipate or get notified when the tableview finishes scrolling.
Can I somehow use timers to check every second if the tableView is scrolling or not?
Upvotes: 20
Views: 23535
Reputation: 3592
You would implement UIScrollViewDelegate
protocol method as follows:
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if (!decelerate) {
[self scrollingFinish];
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
[self scrollingFinish];
}
- (void)scrollingFinish {
//enter code here
}
Swift version
public func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
if decelerate {
scrollingFinished()
}
}
public func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
scrollingFinished()
}
func scrollingFinished() {
print("scrolling finished...")
}
For the above delegate method The scroll view sends this message when the user’s finger touches up after dragging content. The decelerating property of UIScrollView controls deceleration.
When the view decelerated to stop, the parameter decelerate
will be NO
.
Second one used for scrolling slowly, even scrolling stop when your finger touch up, as Apple Documents said, when the scrolling movement comes to a halt
.
Upvotes: 37
Reputation: 3868
After using shanegao's answer and Jovan Stankovic's comment on it, I devised this for Swift3 -
extension NMViewController: UIScrollViewDelegate {
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
if !decelerate {
scrollViewDidEndDecelerating(scrollView)
}
}
func scrollViewDidScrollToTop(_ scrollView: UIScrollView) {
scrollViewDidEndDecelerating(scrollView)
}
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
// Your logic to handle after scrolling is done
}
}
Upvotes: 0
Reputation: 3908
The below code will update you every time when user scrolling stopped.
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
if (!decelerate)
{
if (isScrollingStart)
{
isScrollingStart=NO;
[self scrollingStopped];
}
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
if (isScrollingStart)
{
isScrollingStart=NO;
[self scrollingStopped];
}
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
isScrollingStart=YES;
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
isScrollingStart=YES;
}
-(void)scrollingStopped
{
NSLog(@"Scrolling stopped");
}
Upvotes: 7
Reputation: 1359
UITableView conforms to UIScrollViewDelegate. Please, refer to the documentation of that protocol, it has methods you need.
Upvotes: 0