Skip to content

Instantly share code, notes, and snippets.

@tylerlantern
Created December 27, 2018 08:54
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 tylerlantern/b659346572198f67f7f4a830e7ecc587 to your computer and use it in GitHub Desktop.
Save tylerlantern/b659346572198f67f7f4a830e7ecc587 to your computer and use it in GitHub Desktop.
fileprivate let threshold : CGFloat = 300
@objc func handlePanGesture(sender: UIPanGestureRecognizer) {
let view = sender.view!
let viewTranslation = sender.translation(in: view)
switch sender.state {
case .began:
transitionInProgress = true
presentedViewController.dismiss(animated: true, completion: nil)
break
case .changed:
guard viewTranslation.x < 0 else {
cancel()
return
}
let absX = abs(viewTranslation.x)
const = CGFloat(fminf(fmaxf(Float(absX / threshold), 0), 1.0))
shouldCompleteTransition = const > 0.5
update(const)
break
case .cancelled, .ended , .failed:
if !shouldCompleteTransition || sender.state == .cancelled {
cancel()
} else {
finish()
}
transitionInProgress = false
break
default:
transitionInProgress = false
break
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment