iosswiftuiscrollviewtouchesended

How to implement touchesEnded in a UIScrollView or equivalent


I'm writing a swift iOS app with a paging scroll view. I have a label on the bottom which I intend to update the text of depending on the current page. I'm fine to sort the current page code, but does anybody know how to implement a method to fire whenever the user lifts their finger off of the scroll view.

As far as I know, touchesEnded won't fire because the scroll view is taking up the entire space of the view controller. So the user isn't technically touching the actual view controller.

Any useful tutorials or general instruction would be extremely useful.

Thanks


Solution

  • Create a subclass for your scroll view and implement touchesEnded there. It will be called when you lift your finger (be sure to call super so the normal touch handling occurs). You only need to use this if you want to be notified when the user touches then lifts without scrolling. If you only care about when the user scrolls, then you can use scrollViewDidEndDragging:willDecelerate: and scrollViewDidEndDecelerating.