Alex Tau
Alex Tau

Reputation: 2639

How to detect that UIScrollView is scrolling or that is is dragging

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

Upvotes: 17

Views: 25798

Answers (3)

codrut
codrut

Reputation: 830

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

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

Upvotes: 7

ober
ober

Reputation: 2481

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

func scrollViewDidScroll(_ scrollView: UIScrollView) {

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

Upvotes: 22

Shorhashi
Shorhashi

Reputation: 670

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
}

Upvotes: 27

Related Questions