diff --git a/Sources/SheetController/SheetContainerPresentationAnimationController.swift b/Sources/SheetController/SheetContainerPresentationAnimationController.swift index 1cc50b5..a34184a 100644 --- a/Sources/SheetController/SheetContainerPresentationAnimationController.swift +++ b/Sources/SheetController/SheetContainerPresentationAnimationController.swift @@ -31,22 +31,26 @@ class SheetContainerPresentationAnimationController: NSObject, UIViewControllerA container.addSubview(dimmingView) 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) - 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 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 - toVC.view.transform = .identity - }, completion: { (finished) in + toVC.topConstraint.constant = initialConstant + toVC.view.layoutIfNeeded() + } completion: { (finished) in dimmingView.removeFromSuperview() toVC.dimmingView.isHidden = false toVC.view.frame = finalFrame transitionContext.completeTransition(!transitionContext.transitionWasCancelled) - }) + } }