-
Notifications
You must be signed in to change notification settings - Fork 912
/
HorizVertPanGestureRecognizers.swift
61 lines (49 loc) · 1.95 KB
/
HorizVertPanGestureRecognizers.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import UIKit
// and note use secondary import, essential to import hidden methods
import UIKit.UIGestureRecognizerSubclass
class HorizPanGestureRecognizer : UIPanGestureRecognizer {
var origLoc = CGPoint.zero
override func touchesBegan(_ touches: Set<UITouch>, with e: UIEvent) {
self.origLoc = touches.first!.location(in:self.view!.superview)
super.touchesBegan(touches, with:e)
}
override func touchesMoved(_ touches: Set<UITouch>, with e: UIEvent) {
if self.state == .possible {
let loc = touches.first!.location(in:self.view!.superview)
let deltaX = abs(loc.x - self.origLoc.x)
let deltaY = abs(loc.y - self.origLoc.y)
if deltaY >= deltaX {
self.state = .failed
}
}
super.touchesMoved(touches, with:e)
}
override func translation(in view: UIView?) -> CGPoint {
var proposedTranslation = super.translation(in:view)
proposedTranslation.y = 0
return proposedTranslation
}
}
class VertPanGestureRecognizer : UIPanGestureRecognizer {
var origLoc = CGPoint.zero
override func touchesBegan(_ touches: Set<UITouch>, with e: UIEvent) {
self.origLoc = touches.first!.location(in:self.view!.superview)
super.touchesBegan(touches, with:e)
}
override func touchesMoved(_ touches: Set<UITouch>, with e: UIEvent) {
if self.state == .possible {
let loc = touches.first!.location(in:self.view!.superview)
let deltaX = abs(loc.x - self.origLoc.x)
let deltaY = abs(loc.y - self.origLoc.y)
if deltaX >= deltaY {
self.state = .failed
}
}
super.touchesMoved(touches, with:e)
}
override func translation(in view: UIView?) -> CGPoint {
var proposedTranslation = super.translation(in:view)
proposedTranslation.x = 0
return proposedTranslation
}
}