Use spring animation for presenting sheet
This commit is contained in:
parent
6926446c4e
commit
ece0c5c887
|
@ -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)
|
||||||
})
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue