File tree Expand file tree Collapse file tree 2 files changed +14
-6
lines changed
Sources/DeclarativeLayoutKit/Chaining/Actions Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change 88import UIKit
99
1010
11- /// Add action to a UIGestureRecognizer.
11+ /// **⚠️ Don't forget about ARC when use self or some parent view in action closure, to prevent retain cycle**
1212///
1313/// Using:
1414///
1515/// UIView()
16- /// .addGesture(gesture: UITapGestureRecognizer()
17- /// .addAction {
18- /// // ...
19- /// })
16+ /// .addGesture(UITapGestureRecognizer()
17+ /// .addAction {
18+ /// // ...
19+ /// })
2020extension UIGestureRecognizer {
2121 func addAction( _ action: @escaping ( ) -> Void ) -> Self {
2222 let action = ClosureAction ( attachTo: self , closure: action)
Original file line number Diff line number Diff line change @@ -35,7 +35,15 @@ public extension UIView {
3535 return self
3636 }
3737
38- func addGesture< Gesture: UIGestureRecognizer > ( overwrite: Bool = false , gesture: Gesture ) -> Self {
38+ /// - Parameters:
39+ /// - overwrite: if true - remove previous targets for current event.
40+ @discardableResult
41+ func addGesture< Gesture: UIGestureRecognizer > ( overwrite: Bool = false , _ gesture: Gesture ) -> Self {
42+ isUserInteractionEnabled = true
43+ if overwrite {
44+ gestureRecognizers? . removeAll ( where: { ( gesture: UIGestureRecognizer ) in gesture is Gesture } )
45+ }
46+
3947 addGestureRecognizer ( gesture)
4048 return self
4149 }
You can’t perform that action at this time.
0 commit comments