Created
August 22, 2019 13:33
-
-
Save sagaya/e12f4b05f1b3682c8cd96059899caa88 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 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