Compare commits

...

1 Commits

Author SHA1 Message Date
Shadowfacts ece0c5c887
Use spring animation for presenting sheet 2020-09-10 23:09:47 -04:00
1 changed files with 10 additions and 6 deletions

View File

@ -31,22 +31,26 @@ class SheetContainerPresentationAnimationController: NSObject, UIViewControllerA
container.addSubview(dimmingView) container.addSubview(dimmingView)
container.addSubview(toVC.view) container.addSubview(toVC.view)
toVC.view.transform = CGAffineTransform(translationX: 0, y: toVC.initialConstant) let initialConstant = toVC.initialConstant
toVC.topConstraint.constant = toVC.view.bounds.height
toVC.view.layoutIfNeeded()
let duration = transitionDuration(using: transitionContext) let duration = transitionDuration(using: transitionContext)
UIView.animate(withDuration: duration, animations: { let velocity = 1 / CGFloat(duration)
UIView.animate(withDuration: duration, delay: 0, usingSpringWithDamping: 0.65, initialSpringVelocity: velocity, options: []) {
// we animate the dimming view's frame so that it doesn't go under the content view, in case there's a transparent background // we animate the dimming view's frame so that it doesn't go under the content view, in case there's a transparent background
// we also extend the dimming view under any rounded corners the content view has // we also extend the dimming view under any rounded corners the content view has
dimmingView.frame = CGRect(x: 0, y: 0, width: dimmingView.bounds.width, height: toVC.initialConstant + toVC.content.view.layer.cornerRadius) dimmingView.frame = CGRect(x: 0, y: 0, width: dimmingView.bounds.width, height: initialConstant + toVC.content.view.layer.cornerRadius)
dimmingView.alpha = toVC.dimmingView.alpha dimmingView.alpha = toVC.dimmingView.alpha
toVC.view.transform = .identity toVC.topConstraint.constant = initialConstant
}, completion: { (finished) in toVC.view.layoutIfNeeded()
} completion: { (finished) in
dimmingView.removeFromSuperview() dimmingView.removeFromSuperview()
toVC.dimmingView.isHidden = false toVC.dimmingView.isHidden = false
toVC.view.frame = finalFrame toVC.view.frame = finalFrame
transitionContext.completeTransition(!transitionContext.transitionWasCancelled) transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
}) }
} }