12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- import UIKit
- class ZoomTransitionController: NSObject {
-
- let animator: ZoomAnimator
- let interactionController: ZoomDismissalInteractionController
- var isInteractive: Bool = false
- weak var fromDelegate: ZoomAnimatorDelegate?
- weak var toDelegate: ZoomAnimatorDelegate?
-
- override init() {
- animator = ZoomAnimator()
- interactionController = ZoomDismissalInteractionController()
- super.init()
- }
-
- func didPanWith(gestureRecognizer: UIPanGestureRecognizer) {
- self.interactionController.didPanWith(gestureRecognizer: gestureRecognizer)
- }
- }
- extension ZoomTransitionController: UIViewControllerTransitioningDelegate {
- func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
- self.animator.isPresenting = true
- self.animator.fromDelegate = fromDelegate
- self.animator.toDelegate = toDelegate
- return self.animator
- }
-
- func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
- self.animator.isPresenting = false
- let tmp = self.fromDelegate
- self.animator.fromDelegate = self.toDelegate
- self.animator.toDelegate = tmp
- return self.animator
- }
- func interactionControllerForDismissal(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
- if !self.isInteractive {
- return nil
- }
-
- self.interactionController.animator = animator
- return self.interactionController
- }
- }
- extension ZoomTransitionController: UINavigationControllerDelegate {
- func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationController.Operation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
-
- if operation == .push {
- self.animator.isPresenting = true
- self.animator.fromDelegate = fromDelegate
- self.animator.toDelegate = toDelegate
- } else {
- self.animator.isPresenting = false
- let tmp = self.fromDelegate
- self.animator.fromDelegate = self.toDelegate
- self.animator.toDelegate = tmp
- }
-
- return self.animator
- }
-
- func navigationController(_ navigationController: UINavigationController, interactionControllerFor animationController: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
-
- if !self.isInteractive {
- return nil
- }
-
- self.interactionController.animator = animator
- return self.interactionController
- }
- }
|