简体   繁体   中英

Track pages in paging scrollView

On my iOS app (iOS 11, Swift 4), there is a paging scroll view. To track what page the user is currently is looking at, I am trying to use the scrollViewWillBeginDragging , scrollViewDidEndDragging and scrollViewDidEndDecelerating methods.

However, these seem to not be enough. I'll use an example. Let's say the scrollView has 2 pages, and the user is looking at the one on the most left (index 0).

  • If the user, on single gesture, swipes right, the everything works great (beginDragging is called, then end dragging is called and finally endDecelerating is called)

  • If the user tries to swipe left (to where there is no more pages), when the user releases the touch the UI 'snaps back', as it should. The problem here, is that although didEndDragging is called with its willDecelerate parameter set to true, didEndDecelerating is never called. And this makes me loose track of the page currently being viewed.

I need to know when the users starts to scroll, and when the scrolling stops. Are there any better strategies to achieve this?

Thanks!

You could use the scrollViewDidScroll delegate method, and in there based on the contentOffset you could calculate which page is being shown. Also UIScrollView has isDragging, isDecelerating, etc properties which could help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM