You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
2.6 KiB

  1. // The MIT License (MIT)
  2. //
  3. // Copyright (c) 2016 Luke Zhao <me@lkzhao.com>
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. import UIKit
  23. @objc public protocol HeroViewControllerDelegate {
  24. @objc optional func heroWillStartAnimatingFrom(viewController: UIViewController)
  25. @objc optional func heroDidEndAnimatingFrom(viewController: UIViewController)
  26. @objc optional func heroDidCancelAnimatingFrom(viewController: UIViewController)
  27. @objc optional func heroWillStartTransition()
  28. @objc optional func heroDidEndTransition()
  29. @objc optional func heroDidCancelTransition()
  30. @objc optional func heroWillStartAnimatingTo(viewController: UIViewController)
  31. @objc optional func heroDidEndAnimatingTo(viewController: UIViewController)
  32. @objc optional func heroDidCancelAnimatingTo(viewController: UIViewController)
  33. }
  34. // delegate helper
  35. internal extension HeroTransition {
  36. func closureProcessForHeroDelegate<T: UIViewController>(vc: T, closure: (HeroViewControllerDelegate) -> Void) {
  37. if let delegate = vc as? HeroViewControllerDelegate {
  38. closure(delegate)
  39. }
  40. if let navigationController = vc as? UINavigationController,
  41. let delegate = navigationController.topViewController as? HeroViewControllerDelegate {
  42. closure(delegate)
  43. } else if let tabBarController = vc as? UITabBarController,
  44. let delegate = tabBarController.selectedViewController as? HeroViewControllerDelegate {
  45. closure(delegate)
  46. } else {
  47. for vc in vc.children where vc.isViewLoaded {
  48. self.closureProcessForHeroDelegate(vc: vc, closure: closure)
  49. }
  50. }
  51. }
  52. }