Created
June 20, 2019 15:02
-
-
Save ohlulu/c2cb9b9a4891c79e788c8c784d51bc07 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
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