Created
May 30, 2019 10:13
-
-
Save WildStudio/f58cb27be79a07e7d47c4174f8f10ca7 to your computer and use it in GitHub Desktop.
Adding spring animation with UIViewPropertyAnimator
This file contains 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) { | |
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