SideMenuPresentationStyle.swift 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //
  2. // SideMenuPresentStyle.swift
  3. // SideMenu
  4. //
  5. // Created by Jon Kent on 7/2/19.
  6. //
  7. import UIKit
  8. @objcMembers
  9. open class SideMenuPresentationStyle: InitializableClass {
  10. /// Background color behind the views and status bar color
  11. open var backgroundColor: UIColor = .black
  12. /// The starting alpha value of the menu before it appears
  13. open var menuStartAlpha: CGFloat = 1
  14. /// Whether or not the menu is on top. If false, the presenting view is on top. Shadows are applied to the view on top.
  15. open var menuOnTop: Bool = false
  16. /// The amount the menu is translated along the x-axis. Zero is stationary, negative values are off-screen, positive values are on screen.
  17. open var menuTranslateFactor: CGFloat = 0
  18. /// The amount the menu is scaled. Less than one shrinks the view, larger than one grows the view.
  19. open var menuScaleFactor: CGFloat = 1
  20. /// The color of the shadow applied to the top most view.
  21. open var onTopShadowColor: UIColor = .black
  22. /// The radius of the shadow applied to the top most view.
  23. open var onTopShadowRadius: CGFloat = 5
  24. /// The opacity of the shadow applied to the top most view.
  25. open var onTopShadowOpacity: Float = 0
  26. /// The offset of the shadow applied to the top most view.
  27. open var onTopShadowOffset: CGSize = .zero
  28. /// The ending alpha of the presenting view when the menu is fully displayed.
  29. open var presentingEndAlpha: CGFloat = 1
  30. /// The amount the presenting view is translated along the x-axis. Zero is stationary, negative values are off-screen, positive values are on screen.
  31. open var presentingTranslateFactor: CGFloat = 0
  32. /// The amount the presenting view is scaled. Less than one shrinks the view, larger than one grows the view.
  33. open var presentingScaleFactor: CGFloat = 1
  34. /// The strength of the parallax effect on the presenting view once the menu is displayed.
  35. open var presentingParallaxStrength: CGSize = .zero
  36. required public init() {}
  37. /// This method is called just before the presentation transition begins. Use this to setup any animations. The super method does not need to be called.
  38. open func presentationTransitionWillBegin(to presentedViewController: UIViewController, from presentingViewController: UIViewController) {}
  39. /// This method is called during the presentation animation. Use this to animate anything alongside the menu animation. The super method does not need to be called.
  40. open func presentationTransition(to presentedViewController: UIViewController, from presentingViewController: UIViewController) {}
  41. /// This method is called when the presentation transition ends. Use this to finish any animations. The super method does not need to be called.
  42. open func presentationTransitionDidEnd(to presentedViewController: UIViewController, from presentingViewController: UIViewController, _ completed: Bool) {}
  43. /// This method is called just before the dismissal transition begins. Use this to setup any animations. The super method does not need to be called.
  44. open func dismissalTransitionWillBegin(to presentedViewController: UIViewController, from presentingViewController: UIViewController) {}
  45. /// This method is called during the dismissal animation. Use this to animate anything alongside the menu animation. The super method does not need to be called.
  46. open func dismissalTransition(to presentedViewController: UIViewController, from presentingViewController: UIViewController) {}
  47. /// This method is called when the dismissal transition ends. Use this to finish any animations. The super method does not need to be called.
  48. open func dismissalTransitionDidEnd(to presentedViewController: UIViewController, from presentingViewController: UIViewController, _ completed: Bool) {}
  49. }
  50. public extension SideMenuPresentationStyle {
  51. /// Menu slides in over the existing view.
  52. static var menuSlideIn: SideMenuPresentationStyle {
  53. return SideMenuPresentationStyle {
  54. $0.menuOnTop = true
  55. $0.menuTranslateFactor = -1
  56. }
  57. }
  58. /// The existing view slides out to reveal the menu underneath.
  59. static var viewSlideOut: SideMenuPresentationStyle {
  60. return SideMenuPresentationStyle {
  61. $0.presentingTranslateFactor = 1
  62. }
  63. }
  64. /// The existing view slides out while the menu slides in.
  65. static var viewSlideOutMenuIn: SideMenuPresentationStyle {
  66. return SideMenuPresentationStyle {
  67. $0.menuTranslateFactor = -1
  68. $0.presentingTranslateFactor = 1
  69. }
  70. }
  71. /// The menu dissolves in over the existing view.
  72. static var menuDissolveIn: SideMenuPresentationStyle {
  73. return SideMenuPresentationStyle {
  74. $0.menuStartAlpha = 0
  75. $0.menuOnTop = true
  76. }
  77. }
  78. /// The existing view slides out while the menu partially slides in.
  79. static var viewSlideOutMenuPartialIn: SideMenuPresentationStyle {
  80. return SideMenuPresentationStyle {
  81. $0.menuTranslateFactor = -0.5
  82. $0.presentingTranslateFactor = 1
  83. }
  84. }
  85. /// The existing view slides out while the menu slides out from under it.
  86. static var viewSlideOutMenuOut: SideMenuPresentationStyle {
  87. return SideMenuPresentationStyle {
  88. $0.menuTranslateFactor = 1
  89. $0.presentingTranslateFactor = 1
  90. }
  91. }
  92. /// The existing view slides out while the menu partially slides out from under it.
  93. static var viewSlideOutMenuPartialOut: SideMenuPresentationStyle {
  94. return SideMenuPresentationStyle {
  95. $0.menuTranslateFactor = 0.5
  96. $0.presentingTranslateFactor = 1
  97. }
  98. }
  99. /// The existing view slides out and shrinks to reveal the menu underneath.
  100. static var viewSlideOutMenuZoom: SideMenuPresentationStyle {
  101. return SideMenuPresentationStyle {
  102. $0.presentingTranslateFactor = 1
  103. $0.menuScaleFactor = 0.95
  104. $0.menuOnTop = true
  105. }
  106. }
  107. }