-
-
Save jenox/c5d21761c87d5e92495622c40d4df34d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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