Skip to content

Instantly share code, notes, and snippets.

@okla
Created February 17, 2021 16:36
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save okla/9e0bdadbc2decf72c5eef8e83e1cccba to your computer and use it in GitHub Desktop.
Save okla/9e0bdadbc2decf72c5eef8e83e1cccba to your computer and use it in GitHub Desktop.
SwiftUI DragGesture velocity
extension DragGesture.Value {
var velocity: CGPoint {
let decelerationRate = UIScrollView.DecelerationRate.normal.rawValue,
d = decelerationRate/(1000.0*(1.0 - decelerationRate))
return CGPoint(x: (location.x - predictedEndLocation.x)/d,
y: (location.y - predictedEndLocation.y)/d)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment