In Album Shuffle, you can move and flick albums across the screen. After a user ends a touch event by taking their finger off the screen, the album will still move across the screen as if it were a real physical environment. This article will focus on figuring out how to move the object in a semi-realistic way after the touch event ends. To figure out the velocity of just how fast the object is moving, we’ll need to brush up on some old geometry, which the article will cover. You can take a look at the code used to calculate the motion.
Recording touch information
When a user touches the screen, the view that receives that touch event through the touchesMoved function. The key to figuring out the velocity of the touch is based on how often this function is called. The touchesMoved function isn’t called after the touch moved every pixel, instead the function is called based more or less on time. (Note: if a user touches the screen and doesn’t move their finger, the function won’t be called either because the touch event didn’t move, hence the name touchesMoved. ) If a user touched across a large area of the screen very quickly, then the touchesMoved function might be called two or three times. If that same touch movement was done slowly, then the touchesMoved function might be called 20 or 30 times. The key is that each time an event is sent, the new coordinates are sent. So by remembering the last two touch events sent through the touchesMoved function, based on the gap between these two coordinates, a velocity can be determined.
Geometry Time
So after a touch event occurs, the touchesEnded function is called on the view. At this point, its time to use the last two touch points given to figure out the velocity. Here is where the good old geometry math will help, the distance between these two points is

Distance Between Two Points Formula
The higher this number, the faster and further you need to animate the object across the screen (You’ll need to divide this number by some constant so the object animates proportionate to the motion). The direction can be figured out based on these two points as well. When animating, the time of an animation can be held constant because an object that needs to travel further will travel faster to a spot because it needs to travel a farther distance in a shorter time.