Skip to content

Instantly share code, notes, and snippets.

@jenox
Last active July 9, 2018 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jenox/1a64f711f66f6b0507115ef8a8cf49f6 to your computer and use it in GitHub Desktop.
Save jenox/1a64f711f66f6b0507115ef8a8cf49f6 to your computer and use it in GitHub Desktop.
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