Instantly share code, notes, and snippets.

@jenox /IntendedEndpoint.swift Secret
Last active Jul 9, 2018

What would you like to do?
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