Skip to content

Instantly share code, notes, and snippets.

@jenox
Last active July 9, 2018 12:46
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/c5d21761c87d5e92495622c40d4df34d to your computer and use it in GitHub Desktop.
Save jenox/c5d21761c87d5e92495622c40d4df34d to your computer and use it in GitHub Desktop.
func intendedEndpoint(with velocity: CGVector, from currentPosition: CGPoint) -> Endpoint {
var velocity = velocity
// We want to reduce movement along the secondary axis of the gesture.
if velocity.dx != 0 || velocity.dy != 0 {
let velocityInPrimaryDirection = fmax(fabs(velocity.dx), fabs(velocity.dy))
velocity.dx *= fabs(velocity.dx / velocityInPrimaryDirection)
velocity.dy *= fabs(velocity.dy / velocityInPrimaryDirection)
}
let projectedPosition = UIGestureRecognizer.project(velocity, onto: currentPosition)
let endpoint = self.endpoint(closestTo: projectedPosition)
return endpoint
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment