I would like to reproduce UIScrollView's flick-to-scroll behavior, but I don't want to use (or can't use) that class. What can I do?
Okay, I've answered this by implementing my own library that captures the dynamics of UIScrollView.
What’s useful about my code is that it is independent of coordinate system, animation rate, and particular UI classes that you're using. It can easily be nested in a custom view class of your choosing.
The iPhone’s default flick-to-scroll behavior is interesting. If you hold your finger down for a long time and move it in a variety of directions, you’ll see that only the very last direction is used to compute the scrolling motion.
If you try to build this code yourself, however, you’ll quickly discover that simply using the last two points to compute the direction of motion isn’t going to cut it. Instead, my code keeps a short history of touches and uses linear interpolation to determine where the touch “would have been” some small amount of time ago. This interpolated point is used as the basis for computing the motion vector. This leads to a very pleasing interaction.
The code is available on github, here: http://gist.github.com/100855. It is released under the BSD license.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With