NCZoomTransitionController.swift 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import UIKit
  2. class ZoomTransitionController: NSObject {
  3. let animator: ZoomAnimator
  4. let interactionController: ZoomDismissalInteractionController
  5. var isInteractive: Bool = false
  6. weak var fromDelegate: ZoomAnimatorDelegate?
  7. weak var toDelegate: ZoomAnimatorDelegate?
  8. override init() {
  9. animator = ZoomAnimator()
  10. interactionController = ZoomDismissalInteractionController()
  11. super.init()
  12. }
  13. func didPanWith(gestureRecognizer: UIPanGestureRecognizer) {
  14. self.interactionController.didPanWith(gestureRecognizer: gestureRecognizer)
  15. }
  16. }
  17. extension ZoomTransitionController: UIViewControllerTransitioningDelegate {
  18. func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
  19. self.animator.isPresenting = true
  20. self.animator.fromDelegate = fromDelegate
  21. self.animator.toDelegate = toDelegate
  22. return self.animator
  23. }
  24. func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
  25. self.animator.isPresenting = false
  26. let tmp = self.fromDelegate
  27. self.animator.fromDelegate = self.toDelegate
  28. self.animator.toDelegate = tmp
  29. return self.animator
  30. }
  31. func interactionControllerForDismissal(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
  32. if !self.isInteractive {
  33. return nil
  34. }
  35. self.interactionController.animator = animator
  36. return self.interactionController
  37. }
  38. }
  39. extension ZoomTransitionController: UINavigationControllerDelegate {
  40. func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationController.Operation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
  41. if operation == .push {
  42. self.animator.isPresenting = true
  43. self.animator.fromDelegate = fromDelegate
  44. self.animator.toDelegate = toDelegate
  45. } else {
  46. self.animator.isPresenting = false
  47. let tmp = self.fromDelegate
  48. self.animator.fromDelegate = self.toDelegate
  49. self.animator.toDelegate = tmp
  50. }
  51. return self.animator
  52. }
  53. func navigationController(_ navigationController: UINavigationController, interactionControllerFor animationController: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
  54. if !self.isInteractive {
  55. return nil
  56. }
  57. self.interactionController.animator = animator
  58. return self.interactionController
  59. }
  60. }