-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOYSwipeGesture.swift
41 lines (35 loc) · 979 Bytes
/
OYSwipeGesture.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//
// OYSwipeGesture.swift
// OYExtensions
//
// Created by osmanyildirim
//
import UIKit
/// Swipe gesture with `direction, touchCount, completion handler`
///
/// Usage:
///
/// let swipeGesture = OYSwipeGesture(direction: .up, touchCount: 1) {
/// // do stuff
/// }
/// sampleView.addGestureRecognizer(swipeGesture)
///
/// Remove Swipe gesture:
///
/// swipeGesture.remove()
///
public final class OYSwipeGesture: UISwipeGestureRecognizer, OYBaseGesture {
private var swipeAction: (() -> Void)?
public convenience init(direction: UISwipeGestureRecognizer.Direction, touchCount: Int = 1, completion: (() -> Void)?) {
self.init()
self.direction = direction
#if os(iOS)
numberOfTouchesRequired = touchCount
#endif
swipeAction = completion
addTarget(self, action: #selector(didSwipe))
}
@objc private func didSwipe() {
swipeAction?()
}
}