How to detect that UIScrollView is scrolling or th

2020-06-09 03:52发布

问题:

I need to know on a continuous basis when my UIScrollView is scrolling or dragging.

回答1:

Implement these two delegate methods..

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

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


回答2:

Better use isTracking to detect if the user initiated a touch-drag.

func scrollViewDidScroll(_ scrollView: UIScrollView) {

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


回答3:

This answer is deprecated. See @ober's isTracking solution instead

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