Skip to content

Instantly share code, notes, and snippets.

@tylerlantern
Created December 24, 2018 15:21
Show Gist options
  • Save tylerlantern/6497e29a7bf17310a01870d717c03e73 to your computer and use it in GitHub Desktop.
Save tylerlantern/6497e29a7bf17310a01870d717c03e73 to your computer and use it in GitHub Desktop.
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
let containerView = transitionContext.containerView
transitionContext.viewController(forKey: .from)
let fromVc = transitionContext.viewController(forKey: .from)!
let toVc = transitionContext.viewController(forKey: .to)!
let isPresenting = self.fromViewController == fromVc ? true : false
if isPresenting{
let targetWidth = fromVc.view.frame.width * 0.85
toVc.view.frame = CGRect(x: targetWidth * -1, y: 0, width: targetWidth, height: fromVc.view.frame.height)
containerView.addSubview(toVc.view)
UIView.animate(withDuration: 0.33, animations: {
toVc.view.frame.origin.x = 0
}, completion: { (isDone) in
transitionContext.completeTransition(true)
})
}else {
UIView.animate(withDuration: 0.33, animations: {
fromVc.view.frame.origin.x = fromVc.view.frame.width * -1
}, completion: { (isDone) in
transitionContext.completeTransition(true )
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment