暫無描述

AppearAnimatedTransitioning.swift 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //
  2. // AppearAnimatedTransitioning.swift
  3. // PaiAi
  4. //
  5. // Created by ffib on 2018/12/16.
  6. // Copyright © 2018 yb. All rights reserved.
  7. //
  8. import UIKit
  9. class AppearAnimatedTransitioning: NSObject, UIViewControllerAnimatedTransitioning {
  10. weak var delegate: AlertAnimatorDelegate?
  11. fileprivate var animator: AlertViewAnimatable
  12. init(animator: AlertViewAnimatable) {
  13. self.animator = animator
  14. super.init()
  15. }
  16. func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
  17. return 0.3
  18. }
  19. func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
  20. guard let toVC = transitionContext.viewController(forKey: .to),
  21. let toView = toVC.view,
  22. let contentView = delegate?.getContentView() else { return }
  23. transitionContext.containerView.addSubview(toView)
  24. let duration = transitionDuration(using: transitionContext)
  25. animator.toViewPresentedAnimation(duration: duration, in: toView)
  26. animator.contentViewAppearAnimation(duration: duration, in: contentView)
  27. DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + duration) {
  28. let isCancelled = transitionContext.transitionWasCancelled
  29. transitionContext.completeTransition(!isCancelled)
  30. }
  31. }
  32. }