Skip to content

Commit a82f9b9

Browse files
committed
simplify using uigestureRecognizer + uiview additions
1 parent 4093c65 commit a82f9b9

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// UIGestureRecognizer+Action.swift
3+
//
4+
//
5+
// Created by uuttff8 on 13.07.2021.
6+
//
7+
8+
import UIKit
9+
10+
11+
/// Add action to a UIGestureRecognizer.
12+
///
13+
/// Using:
14+
///
15+
/// UIView()
16+
/// .addGesture(gesture: UITapGestureRecognizer()
17+
/// .addAction {
18+
/// // ...
19+
/// })
20+
extension UIGestureRecognizer {
21+
func addAction(_ action: @escaping () -> Void) -> Self {
22+
let action = ClosureAction(attachTo: self, closure: action)
23+
self.addTarget(action, action: ClosureAction.selector)
24+
return self
25+
}
26+
}

Sources/DeclarativeLayoutKit/Chaining/Actions/UIView+Gesture.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,9 @@ public extension UIView {
3434
addGestureRecognizer(UILongPressGestureRecognizer(target: action, action: ClosureAction.selector))
3535
return self
3636
}
37+
38+
func addGesture<Gesture: UIGestureRecognizer>(overwrite: Bool = false, gesture: Gesture) -> Self {
39+
addGestureRecognizer(gesture)
40+
return self
41+
}
3742
}

0 commit comments

Comments
 (0)