AnimatableViewController.swift 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //
  2. // Created by Jake Lin on 12/14/15.
  3. // Copyright © 2015 IBAnimatable. All rights reserved.
  4. //
  5. import UIKit
  6. @IBDesignable
  7. open class AnimatableViewController: UIViewController, ViewControllerDesignable, StatusBarDesignable, RootWindowDesignable, TransitionAnimatable {
  8. // MARK: - ViewControllerDesignable
  9. @IBInspectable open var hideNavigationBar: Bool = false
  10. // MARK: - StatusBarDesignable
  11. @IBInspectable open var lightStatusBar: Bool = false
  12. // MARK: - RootWindowDesignable
  13. @IBInspectable open var rootWindowBackgroundColor: UIColor?
  14. // MARK: - TransitionAnimatable
  15. @IBInspectable var _transitionAnimationType: String? {
  16. didSet {
  17. if let _transitionAnimationType = _transitionAnimationType {
  18. transitionAnimationType = TransitionAnimationType(string: _transitionAnimationType)
  19. }
  20. }
  21. }
  22. open var transitionAnimationType: TransitionAnimationType = .none
  23. @IBInspectable open var transitionDuration: Double = .nan
  24. open var interactiveGestureType: InteractiveGestureType = .none
  25. @IBInspectable var _interactiveGestureType: String? {
  26. didSet {
  27. if let _interactiveGestureType = _interactiveGestureType {
  28. interactiveGestureType = InteractiveGestureType(string: _interactiveGestureType)
  29. }
  30. }
  31. }
  32. // MARK: - Lifecylce
  33. open override func viewWillAppear(_ animated: Bool) {
  34. super.viewWillAppear(animated)
  35. configureHideNavigationBar()
  36. configureRootWindowBackgroundColor()
  37. }
  38. open override func viewWillDisappear(_ animated: Bool) {
  39. super.viewWillDisappear(animated)
  40. resetHideNavigationBar()
  41. }
  42. open override var preferredStatusBarStyle: UIStatusBarStyle {
  43. if lightStatusBar {
  44. return .lightContent
  45. }
  46. return .default
  47. }
  48. open override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  49. super.prepare(for: segue, sender: sender)
  50. // Configure custom transition animation
  51. guard (segue.destination is PresentationDesignable) == false else {
  52. return
  53. }
  54. if case .none = transitionAnimationType {
  55. return
  56. }
  57. let toViewController = segue.destination
  58. // If interactiveGestureType hasn't been set
  59. let transitionManager = TransitionPresenterManager.shared
  60. if case .none = interactiveGestureType {
  61. toViewController.transitioningDelegate = transitionManager.retrievePresenter(transitionAnimationType: transitionAnimationType,
  62. transitionDuration: transitionDuration)
  63. } else {
  64. toViewController.transitioningDelegate = transitionManager.retrievePresenter(transitionAnimationType: transitionAnimationType,
  65. transitionDuration: transitionDuration,
  66. interactiveGestureType: interactiveGestureType)
  67. }
  68. }
  69. }