Skip to content

Instantly share code, notes, and snippets.

@WildStudio
Created May 30, 2019 10:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WildStudio/f58cb27be79a07e7d47c4174f8f10ca7 to your computer and use it in GitHub Desktop.
Save WildStudio/f58cb27be79a07e7d47c4174f8f10ca7 to your computer and use it in GitHub Desktop.
Adding spring animation with UIViewPropertyAnimator
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
guard let toViewController = transitionContext
.viewController(forKey: .to) as? DetailViewController else { return }
let animator = UIViewPropertyAnimator(duration: Constant.duration, dampingRatio: 0.82)
let container = transitionContext.containerView
container.addSubview(toViewController.view)
let offscreenY = toViewController.view.bounds.height - toViewController.view.frame.minY + 20
toViewController.positionContainer(left: 20.0,
right: 20.0,
top: offscreenY,
bottom: 0.0)
toViewController.view.backgroundColor = .clear
toViewController.setRoundedCorners(isRounded: true)
animator.addAnimations {
toViewController.positionContainer(left: 20.0,
right: 20.0,
top: 40.0,
bottom: 0.0)
toViewController.view.backgroundColor = Constant.backgroundColor
toViewController.setRoundedCorners(isRounded: true)
toViewController.addSpringAnimation(true)
}
animator.addCompletion { _ in
toViewController.addSpringAnimation(false)
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
}
animator.startAnimation()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment