如何检测UIScrollView是滚动还是拖动

时间:2012-06-13 13:28:49

标签: objective-c ios

当我的UIScrollView滚动或拖动时,我需要持续了解。

3 个答案:

答案 0 :(得分:26)

实现这两个委托方法..

- (void)scrollViewDidScroll:(UIScrollView *)sender{
  //executes when you scroll the scrollView
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
 // execute when you drag the scrollView
}

答案 1 :(得分:12)

更好地使用isTracking

func scrollViewDidScroll(_ scrollView: UIScrollView) {

    if scrollView.isTracking {   
    // ... 
    }
}

答案 2 :(得分:6)

@ Shorhashi解决方案的替代方案:

- (void)scrollViewDidScroll:(UIScrollView *)sender{
    if(sender.isDragging) {
        //is dragging
    }
    else {
        //is just scrolling
    } 
}