SwipeTableViewCell+Display.swift 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // SwipeTableViewCell+Display.swift
  3. //
  4. // Created by Jeremy Koch
  5. // Copyright © 2017 Jeremy Koch. All rights reserved.
  6. //
  7. import UIKit
  8. extension SwipeTableViewCell {
  9. /// The point at which the origin of the cell is offset from the non-swiped origin.
  10. public var swipeOffset: CGFloat {
  11. set { setSwipeOffset(newValue, animated: false) }
  12. get { return frame.midX - bounds.midX }
  13. }
  14. /**
  15. Hides the swipe actions and returns the cell to center.
  16. - parameter animated: Specify `true` to animate the hiding of the swipe actions or `false` to hide it immediately.
  17. - parameter completion: The closure to be executed once the animation has finished. A `Boolean` argument indicates whether or not the animations actually finished before the completion handler was called.
  18. */
  19. public func hideSwipe(animated: Bool, completion: ((Bool) -> Void)? = nil) {
  20. swipeController.hideSwipe(animated: animated, completion: completion)
  21. }
  22. /**
  23. Shows the swipe actions for the specified orientation.
  24. - parameter orientation: The side of the cell on which to show the swipe actions.
  25. - parameter animated: Specify `true` to animate the showing of the swipe actions or `false` to show them immediately.
  26. - parameter completion: The closure to be executed once the animation has finished. A `Boolean` argument indicates whether or not the animations actually finished before the completion handler was called.
  27. */
  28. public func showSwipe(orientation: SwipeActionsOrientation, animated: Bool = true, completion: ((Bool) -> Void)? = nil) {
  29. setSwipeOffset(.greatestFiniteMagnitude * orientation.scale * -1,
  30. animated: animated,
  31. completion: completion)
  32. }
  33. /**
  34. The point at which the origin of the cell is offset from the non-swiped origin.
  35. - parameter offset: A point (expressed in points) that is offset from the non-swiped origin.
  36. - parameter animated: Specify `true` to animate the transition to the new offset, `false` to make the transition immediate.
  37. - parameter completion: The closure to be executed once the animation has finished. A `Boolean` argument indicates whether or not the animations actually finished before the completion handler was called.
  38. */
  39. public func setSwipeOffset(_ offset: CGFloat, animated: Bool = true, completion: ((Bool) -> Void)? = nil) {
  40. swipeController.setSwipeOffset(offset, animated: animated, completion: completion)
  41. }
  42. }