BlockPan.swift 780 B

1234567891011121314151617181920212223242526272829303132
  1. //
  2. // BlockPan.swift
  3. //
  4. //
  5. // Created by Cem Olcay on 12/08/15.
  6. //
  7. //
  8. #if os(iOS) || os(tvOS)
  9. import UIKit
  10. ///Make sure you use "[weak self] (gesture) in" if you are using the keyword self inside the closure or there might be a memory leak
  11. open class BlockPan: UIPanGestureRecognizer {
  12. private var panAction: ((UIPanGestureRecognizer) -> Void)?
  13. public override init(target: Any?, action: Selector?) {
  14. super.init(target: target, action: action)
  15. }
  16. public convenience init (action: ((UIPanGestureRecognizer) -> Void)?) {
  17. self.init()
  18. self.panAction = action
  19. self.addTarget(self, action: #selector(BlockPan.didPan(_:)))
  20. }
  21. @objc open func didPan (_ pan: UIPanGestureRecognizer) {
  22. panAction? (pan)
  23. }
  24. }
  25. #endif