Created
August 22, 2019 14:07
-
-
Save sagaya/7cf5d2c6e226dc5d2efa4ac61efcb4d3 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 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