BlockPinch.swift 796 B

1234567891011121314151617181920212223242526272829303132
  1. //
  2. // BlockPinch.swift
  3. //
  4. //
  5. // Created by Cem Olcay on 12/08/15.
  6. //
  7. //
  8. #if os(iOS)
  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 BlockPinch: UIPinchGestureRecognizer {
  12. private var pinchAction: ((UIPinchGestureRecognizer) -> Void)?
  13. public override init(target: Any?, action: Selector?) {
  14. super.init(target: target, action: action)
  15. }
  16. public convenience init (action: ((UIPinchGestureRecognizer) -> Void)?) {
  17. self.init()
  18. self.pinchAction = action
  19. self.addTarget(self, action: #selector(BlockPinch.didPinch(_:)))
  20. }
  21. @objc open func didPinch (_ pinch: UIPinchGestureRecognizer) {
  22. pinchAction? (pinch)
  23. }
  24. }
  25. #endif