Compare commits
1 Commits
7ac34efeab
...
ece0c5c887
Author | SHA1 | Date |
---|---|---|
Shadowfacts | ece0c5c887 |
|
@ -11,7 +11,7 @@ import UIKit
|
||||||
class SheetContainerDismissAnimationController: NSObject, UIViewControllerAnimatedTransitioning {
|
class SheetContainerDismissAnimationController: NSObject, UIViewControllerAnimatedTransitioning {
|
||||||
|
|
||||||
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
|
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
|
||||||
return 0.5
|
return 0.35
|
||||||
}
|
}
|
||||||
|
|
||||||
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
|
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
|
||||||
|
@ -36,8 +36,7 @@ class SheetContainerDismissAnimationController: NSObject, UIViewControllerAnimat
|
||||||
|
|
||||||
if let initialVelocity = fromVC.dismissAnimationInitialVelocity {
|
if let initialVelocity = fromVC.dismissAnimationInitialVelocity {
|
||||||
let vector = CGVector(dx: initialVelocity, dy: 0)
|
let vector = CGVector(dx: initialVelocity, dy: 0)
|
||||||
let damping = SheetContainerViewController.springDamping
|
let parameters = UISpringTimingParameters(dampingRatio: 1, initialVelocity: vector)
|
||||||
let parameters = UISpringTimingParameters(dampingRatio: damping, initialVelocity: vector)
|
|
||||||
animator = UIViewPropertyAnimator(duration: duration, timingParameters: parameters)
|
animator = UIViewPropertyAnimator(duration: duration, timingParameters: parameters)
|
||||||
} else {
|
} else {
|
||||||
animator = UIViewPropertyAnimator(duration: duration, curve: .easeOut)
|
animator = UIViewPropertyAnimator(duration: duration, curve: .easeOut)
|
||||||
|
|
|
@ -11,7 +11,7 @@ import UIKit
|
||||||
class SheetContainerPresentationAnimationController: NSObject, UIViewControllerAnimatedTransitioning {
|
class SheetContainerPresentationAnimationController: NSObject, UIViewControllerAnimatedTransitioning {
|
||||||
|
|
||||||
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
|
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
|
||||||
return 0.5
|
return 0.35
|
||||||
}
|
}
|
||||||
|
|
||||||
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
|
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
|
||||||
|
@ -36,10 +36,8 @@ class SheetContainerPresentationAnimationController: NSObject, UIViewControllerA
|
||||||
toVC.view.layoutIfNeeded()
|
toVC.view.layoutIfNeeded()
|
||||||
|
|
||||||
let duration = transitionDuration(using: transitionContext)
|
let duration = transitionDuration(using: transitionContext)
|
||||||
let damping = SheetContainerViewController.springDamping
|
let velocity = 1 / CGFloat(duration)
|
||||||
let pointsPerSecond: CGFloat = 50
|
UIView.animate(withDuration: duration, delay: 0, usingSpringWithDamping: 0.65, initialSpringVelocity: velocity, options: []) {
|
||||||
let velocity = pointsPerSecond / initialConstant
|
|
||||||
UIView.animate(withDuration: duration, delay: 0, usingSpringWithDamping: damping, 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: initialConstant + toVC.content.view.layer.cornerRadius)
|
dimmingView.frame = CGRect(x: 0, y: 0, width: dimmingView.bounds.width, height: initialConstant + toVC.content.view.layer.cornerRadius)
|
||||||
|
|
|
@ -31,8 +31,6 @@ public extension SheetContainerViewControllerDelegate {
|
||||||
|
|
||||||
open class SheetContainerViewController: UIViewController {
|
open class SheetContainerViewController: UIViewController {
|
||||||
|
|
||||||
internal static let springDamping: CGFloat = 0.75
|
|
||||||
|
|
||||||
public weak var delegate: SheetContainerViewControllerDelegate?
|
public weak var delegate: SheetContainerViewControllerDelegate?
|
||||||
|
|
||||||
public let content: UIViewController
|
public let content: UIViewController
|
||||||
|
@ -226,8 +224,7 @@ open class SheetContainerViewController: UIViewController {
|
||||||
if delegate?.sheetContainer(self, willSnapToDetent: springToDetent.0) ?? true {
|
if delegate?.sheetContainer(self, willSnapToDetent: springToDetent.0) ?? true {
|
||||||
self.topConstraint.constant = springToDetent.1
|
self.topConstraint.constant = springToDetent.1
|
||||||
|
|
||||||
let damping = SheetContainerViewController.springDamping
|
UIView.animate(withDuration: 0.35, delay: 0, usingSpringWithDamping: 0.75, initialSpringVelocity: springVelocity, animations: {
|
||||||
UIView.animate(withDuration: 0.35, delay: 0, usingSpringWithDamping: damping, initialSpringVelocity: springVelocity, animations: {
|
|
||||||
self.view.layoutIfNeeded()
|
self.view.layoutIfNeeded()
|
||||||
self.dimmingView.alpha = lerp(springToDetent.1, min: self.topDetent.offset, max: self.bottomDetent.offset, from: self.maximumDimmingAlpha, to: self.minimumDimmingAlpha)
|
self.dimmingView.alpha = lerp(springToDetent.1, min: self.topDetent.offset, max: self.bottomDetent.offset, from: self.maximumDimmingAlpha, to: self.minimumDimmingAlpha)
|
||||||
}, completion: { (finished) in
|
}, completion: { (finished) in
|
||||||
|
|
Loading…
Reference in New Issue