Instantly share code, notes, and snippets.

Embed
What would you like to do?
Projection assuming an exponentially decreasing velocity.
extension UIGestureRecognizer {
public static func project(_ velocity: CGFloat, onto position: CGFloat, decelerationRate: UIScrollView.DecelerationRate = .normal) -> CGFloat {
let factor = -1 / (1000 * log(decelerationRate.rawValue))
return position + factor * velocity
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment