12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- //
- // BlockTap.swift
- //
- //
- // Created by Cem Olcay on 12/08/15.
- //
- //
- #if os(iOS) || os(tvOS)
- import UIKit
- ///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
- open class BlockTap: UITapGestureRecognizer {
- private var tapAction: ((UITapGestureRecognizer) -> Void)?
- public override init(target: Any?, action: Selector?) {
- super.init(target: target, action: action)
- }
- public convenience init (
- tapCount: Int = 1,
- fingerCount: Int = 1,
- action: ((UITapGestureRecognizer) -> Void)?) {
- self.init()
- self.numberOfTapsRequired = tapCount
- #if os(iOS)
- self.numberOfTouchesRequired = fingerCount
- #endif
- self.tapAction = action
- self.addTarget(self, action: #selector(BlockTap.didTap(_:)))
- }
- @objc open func didTap (_ tap: UITapGestureRecognizer) {
- tapAction? (tap)
- }
- }
- #endif
|