Created
May 15, 2018 21:46
-
-
Save harrysummers/4a1af1d488d2dd4928095b5ab803d9c1 to your computer and use it in GitHub Desktop.
Sliding Left Transition Animation
This file contains hidden or 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
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { | |
let containerView = transitionContext.containerView | |
let toView = transitionContext.view(forKey: .to)! | |
let fromView = transitionContext.view(forKey: .from)! | |
let slideTransform = CGAffineTransform(translationX: toView.frame.width, y: 0) | |
toView.transform = slideTransform | |
let finalFrame = CGRect(x: -fromView.frame.width, y: 0, width: fromView.frame.width, height: fromView.frame.height) | |
containerView.addSubview(toView) | |
containerView.bringSubview(toFront: toView) | |
UIView.animate(withDuration: duration, delay:0.0, | |
usingSpringWithDamping: 0.4, initialSpringVelocity: 0.0, | |
animations: { | |
toView.transform = .identity | |
fromView.frame = finalFrame | |
}, | |
completion: { _ in | |
transitionContext.completeTransition(true) | |
} | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment