Skip to content

Instantly share code, notes, and snippets.

@sagaya
Created August 22, 2019 14:07
Show Gist options
  • Save sagaya/7cf5d2c6e226dc5d2efa4ac61efcb4d3 to your computer and use it in GitHub Desktop.
Save sagaya/7cf5d2c6e226dc5d2efa4ac61efcb4d3 to your computer and use it in GitHub Desktop.
class PopAnimation: NSObject, UIViewControllerAnimatedTransitioning {
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return 0.5
}
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
guard let fromViewController = transitionContext.viewController(forKey: .from), let toViewController = transitionContext.viewController(forKey: .to) else { return }
let window = UIScreen.main.bounds
transitionContext.containerView.insertSubview(toViewController.view, belowSubview: fromViewController.view)
let duration = self.transitionDuration(using: transitionContext)
UIView.animate(withDuration: duration, animations: {
fromViewController.view.transform = .init(translationX: window.size.width, y: 1)
toViewController.view.transform = .identity
}, completion: { _ in
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment