Skip to content

Instantly share code, notes, and snippets.

@Bashta
Last active February 8, 2016 12:18
Show Gist options
  • Save Bashta/87ba80e53eebb7b92696 to your computer and use it in GitHub Desktop.
Save Bashta/87ba80e53eebb7b92696 to your computer and use it in GitHub Desktop.
final class InteractiveSwipe: UIPercentDrivenInteractiveTransition {
var panGesture: UIPanGestureRecognizer?
weak var viewController: UIViewController?
private var shouldComplete = true
func attachToViewController(viewController: UIViewController) {
self.viewController = viewController
panGesture = UIPanGestureRecognizer(target:self, action: "onPan:")
self.viewController?.view.addGestureRecognizer(panGesture!)
}
func onPan(pan: UIPanGestureRecognizer) {
let translation = pan.translationInView(pan.view?.superview)
switch pan.state {
case .Began: break
self.viewController?.dismissViewControllerAnimated(true, completion: nil)
case .Changed:
let dragAmount: CGFloat = 50
let threshHold: CGFloat = 0.5
var percentage: CGFloat = translation.x / dragAmount
percentage = CGFloat(fmaxf(Float(percentage), 0.0))
percentage = CGFloat(fminf(Float(percentage), 1.0))
self.updateInteractiveTransition(percentage)
shouldComplete = percentage >= threshHold
print(shouldComplete)
print(percentage)
case .Ended:
self.finishInteractiveTransition()
case .Cancelled:
self.cancelInteractiveTransition()
default:
return
}
}
@nonobjc
func completionSpeed() -> CGFloat {
return 1 - self.percentComplete
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment