20

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?

4

4 回答 4

37

您将按UIScrollViewDelegate如下方式实现协议方法:

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
    if (!decelerate) {
        [self scrollingFinish];
    }
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    [self scrollingFinish];
}

- (void)scrollingFinish {
    //enter code here
}

斯威夫特版本

public func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
    if decelerate {
        scrollingFinished()
    }
}

public func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
    scrollingFinished()
}

func scrollingFinished() {
    print("scrolling finished...")
}

对于上述委托方法,The scroll view sends this message when the user’s finger touches up after dragging content. The decelerating property of UIScrollView controls deceleration.当视图减速停止时,参数decelerate将为NO.

第二个用于缓慢滚动,甚至当您的手指触摸时滚动停止,正如 Apple Documents 所说,when the scrolling movement comes to a halt.

于 2013-05-13T12:14:10.950 回答
7

每次用户滚动停止时,以下代码都会更新您。

- (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");
}
于 2016-01-08T15:50:45.467 回答
1

UITableView 符合 UIScrollViewDelegate。请参阅该协议的文档,它有您需要的方法。

于 2013-05-13T12:11:34.487 回答
0

在使用了 shanegao 的回答和 Jovan Stankovic 对此的评论后,我为 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
    }
}
于 2017-10-05T08:57:14.010 回答