scrolluiscrollviewuipagecontrol

Inertial scrolling in UIPageControl with UIScrollView


I have a UIScrollView with paging enabled, and a corresponding UIPageControl to indicate the current page. This works well, but I'd like to introduce inertial scrolling to navigate multiple pages with one swipe.

One example I've seen of this is the StickTennis app for iOS. How can I do something similar?

See Image


Solution

  • You'd set the pagingEnabled property of the scroll view to NO, then you'd calculate the speed of the scrolling at the moment the user's finger leaves the screen using numerical derivation. From now on, you could use the s = v0 * t + a / 2 * t ^ 2 formula to calculate the new position of the scroll view (when a is a constant deceleration rate and v0 is the speed you just calculated), and then you'd repeatedly call scrollRectToVisible:animated: with an appropriately updated rect argument.