Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 360
Alex Tau Avatar asked Jun 13 '12 13:06

Alex Tau


People also ask

How do I know if ScrollView is scrolling?

When you call [setContentOffset:animated:] , it's passing that off to the UIScrollView as a CABasicAnimation , manipulating the bounds property. Granted, this check will also return true if the shape of the scroll view itself is animating.

How can I tell if ScrollView is scrolling Android?

Do you know if it is possible to know if an Android Widget ScrollView can scroll? If it has enough space it doesn't need to scroll, but as soon as a dimension exceeds a maximum value the widget can scroll.

How do you scroll on a storyboard?

You can scroll the scrollview in the Storyboard / Interface builder! Select the view inside scrollview in Document Outline, then scroll using your mouse or trackpad, you can see the view move.

What is scroll view in Swift?

The scroll view displays its content within the scrollable content region. As the user performs platform-appropriate scroll gestures, the scroll view adjusts what portion of the underlying content is visible. ScrollView can scroll horizontally, vertically, or both, but does not provide zooming functionality.


2 Answers

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
}
like image 154
Shorhashi Avatar answered Sep 22 '22 13:09

Shorhashi


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

func scrollViewDidScroll(_ scrollView: UIScrollView) {

    if scrollView.isTracking {   
    // ... 
    }
}
like image 39
ober Avatar answered Sep 18 '22 13:09

ober