Skip to content

Instantly share code, notes, and snippets.

@WildStudio
Created May 29, 2019 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WildStudio/9d77bf694e1aa04893e2e0458868c87c to your computer and use it in GitHub Desktop.
Save WildStudio/9d77bf694e1aa04893e2e0458868c87c to your computer and use it in GitHub Desktop.
Presentation transition animation
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
guard let toViewController = transitionContext
.viewController(forKey: .to) as? DetailViewController else { return }
let container = transitionContext.containerView
container.addSubview(toViewController.view)
toViewController.positionContainer(left: 20.0,
right: 20.0,
top: selectedCardFrame.origin.y + 20.0,
bottom: 0.0)
toViewController.view.backgroundColor = .clear
toViewController.setRoundedCorners(isRounded: false)
let duration = transitionDuration(using: transitionContext)
UIView.animate(withDuration: duration, animations: {
toViewController.positionContainer(left: 20.0,
right: 20.0,
top: 20.0,
bottom: 0.0)
toViewController.view.backgroundColor = Constant.backgroundColor
toViewController.setRoundedCorners(isRounded: true)
}) { (_) in
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment