When your UIPanGestureRecognizer state becomes UIGestureRecognizerStateEnded , use the message velocityInView: to find the speed of gestures.
If the speed is close to zero, open or close the view depending on the position of the view and the previous state of the view. For example, if the view was closed and it was taken out more than 10%, open it. If it was opened and pulled out more than 10%, close it. Otherwise, return it to the position of preliminary gestures.
If the speed is not close to zero, use the sign of the Y component to determine the new state of the view. If the sign is positive, close the view. If the sign is negative, open the view.
You will need to experiment to determine exactly which βclose to zeroβ definition is best.
In any case, you need to animate the view to its final position after gestures, using a short duration (probably between 0.1 and 0.25 seconds). You can choose the duration based on the speed and distance you want to view. The system notification panel does this. (Try dragging it partially down slowly and quickly. It revives its final position at different speeds depending on how fast you drag it when you release it.)
You need to experiment to find the best animation curve ( UIViewAnimationOptionCurveEaseOut , etc.), and you can use a different curve depending on whether you open or close the view and gesture speed.
source share