Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save harrysummers/4a1af1d488d2dd4928095b5ab803d9c1 to your computer and use it in GitHub Desktop.
Save harrysummers/4a1af1d488d2dd4928095b5ab803d9c1 to your computer and use it in GitHub Desktop.
Sliding Left Transition Animation
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