Skip to content

Instantly share code, notes, and snippets.

@ohlulu
Created June 20, 2019 15:02
Show Gist options
  • Save ohlulu/c2cb9b9a4891c79e788c8c784d51bc07 to your computer and use it in GitHub Desktop.
Save ohlulu/c2cb9b9a4891c79e788c8c784d51bc07 to your computer and use it in GitHub Desktop.
class UpToDownIneraction: UIPercentDrivenInteractiveTransition {
// ...
@objc func handleGesture(_ gestureRecoginizer: UIPanGestureRecognizer) {
let gestureView = gestureRecoginizer.view!
let trainsiton = gestureRecoginizer.translation(in: gestureView)
switch gestureRecoginizer.state {
case .began:
print("began")
interacting = true
if let naviController = presentingViewController?.navigationController {
naviController.popViewController(animated: true)
} else {
presentingViewController?.dismiss(animated: true, completion: nil)
}
case .changed:
var fraction = trainsiton.y / gestureView.frame.height
print("\(fraction)")
fraction = max(fraction, 0.0)
fraction = min(fraction, 1)
couldComplete = fraction > 0.4
update(fraction)
case .cancelled, .ended:
interacting = false
if couldComplete == false || gestureRecoginizer.state == .cancelled {
cancel()
} else {
finish()
}
default:
break
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment