Skip to content

Instantly share code, notes, and snippets.

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