No Description

ViewControllerTransitioningProxy.swift 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //
  2. // ViewControllerTransitioningProxy.swift
  3. // PaiaiUIKit
  4. //
  5. // Created by ffib on 2019/1/28.
  6. // Copyright © 2019 yb. All rights reserved.
  7. //
  8. import Foundation
  9. class ViewControllerTransitioningProxy: NSObject, UIViewControllerTransitioningDelegate {
  10. weak var delegate: ViewControllerTransitioningDelegate?
  11. init(target: ViewControllerTransitioningDelegate) {
  12. delegate = target
  13. }
  14. func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
  15. return delegate?.animationController(forDismissed: dismissed)
  16. }
  17. func animationController(forPresented presented: UIViewController,
  18. presenting: UIViewController,
  19. source: UIViewController)
  20. -> UIViewControllerAnimatedTransitioning? {
  21. return delegate?.animationController(forPresented: presented,
  22. presenting: presenting,
  23. source: source)
  24. }
  25. }
  26. extension UIViewController {
  27. private struct AssociatedKeys {
  28. static var proxyKey = "ViewControllerTransitioningProxyKey"
  29. }
  30. private var proxy: ViewControllerTransitioningProxy? {
  31. get { return objc_getAssociatedObject(self, &AssociatedKeys.proxyKey) as? ViewControllerTransitioningProxy }
  32. set { objc_setAssociatedObject(self, &AssociatedKeys.proxyKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) }
  33. }
  34. func setTransitioningDelegate<T: ViewControllerTransitioningDelegate>(_ target: T) {
  35. proxy = ViewControllerTransitioningProxy(target: target)
  36. transitioningDelegate = proxy
  37. }
  38. }