12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- import UIKit
- class AppearAnimatedTransitioning: 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 toVC = transitionContext.viewController(forKey: .to),
- let toView = toVC.view,
- let contentView = delegate?.getContentView() else { return }
- transitionContext.containerView.addSubview(toView)
-
- let duration = transitionDuration(using: transitionContext)
-
- animator.toViewPresentedAnimation(duration: duration, in: toView)
- animator.contentViewAppearAnimation(duration: duration, in: contentView)
-
- DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + duration) {
- let isCancelled = transitionContext.transitionWasCancelled
- transitionContext.completeTransition(!isCancelled)
- }
- }
- }
|