如何监测UITableView等UIScrollView滑动停止呢?
有两种方式:
第一种:
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if (!decelerate) {
BOOL dragToDragStop = scrollView.tracking && !scrollView.dragging && !scrollView.decelerating;
if (dragToDragStop) {
[self scrollViewDidEndScroll];
}
}
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
BOOL scrollToScrollStop = !scrollView.tracking && !scrollView.dragging && !scrollView.decelerating;
if (scrollToScrollStop) {
[self scrollViewDidEndScroll];
}
}
- (void)scrollViewDidEndScroll {
//在这里写监听滑动停止要做的事
}
第二种:
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
if ([self.mainDelegate respondsToSelector:@selector(mainScrollViewDidScroll:)]) {
[self.mainDelegate mainScrollViewDidScroll:scrollView];
}
[NSObject cancelPreviousPerformRequestsWithTarget:self];
[self performSelector:@selector(scrollViewDidEndScrollingAnimation:) withObject:nil afterDelay:0.1];
}
-(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
{
[NSObject cancelPreviousPerformRequestsWithTarget:self];
//在这里写监听滑动停止要做的事
}
参考:
Hook系统代理方法,添加UIScrollView滚动停止回调
iphone - How to detect when a UIScrollView has finished scrolling - Stack Overflow
网友评论