AnimatableTableViewController.swift 3.4 KB

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