12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import UIKit
- class DisappearAnimatedTransitioning: NSObject, UIViewControllerAnimatedTransitioning {
- weak var delegate: AlertAnimatorDelegate?
- fileprivate var animator: AlertViewAnimatable
-
- init(animator: AlertViewAnimatable) {
- self.animator = animator
- super.init()
- }
-
- func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
- return 0.3
- }
-
- func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
- guard let fromVC = transitionContext.viewController(forKey: .from),
- let fromView = fromVC.view,
- let toVC = transitionContext.viewController(forKey: .to),
- let toView = toVC.view,
- let contentView = delegate?.getContentView() else { return }
- let duration = transitionDuration(using: transitionContext)
-
- animator.fromViewPresentingAnimation(duration: duration, in: fromView)
- animator.contentViewDisappearAnimation(duration: duration, in: contentView)
-
- DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + duration) {
- let isCancelled = transitionContext.transitionWasCancelled
- transitionContext.completeTransition(!isCancelled)
- transitionContext.containerView.addSubview(toView)
- fromView.removeFromSuperview()
- }
- }
- }
|