mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
952 B
Swift
39 lines
952 B
Swift
8 years ago
|
//
|
||
|
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||
|
//
|
||
|
|
||
|
import UIKit.UIGestureRecognizerSubclass
|
||
|
|
||
|
@objc
|
||
|
enum PanDirection: Int {
|
||
|
case vertical
|
||
|
case horizontal
|
||
|
}
|
||
|
|
||
|
@objc
|
||
|
class PanDirectionGestureRecognizer: UIPanGestureRecognizer {
|
||
|
|
||
|
let direction: PanDirection
|
||
|
|
||
|
init(direction: PanDirection, target: AnyObject, action: Selector) {
|
||
|
self.direction = direction
|
||
|
super.init(target: target, action: action)
|
||
|
}
|
||
|
|
||
|
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent) {
|
||
|
super.touchesMoved(touches, with: event)
|
||
|
|
||
|
if state == .began {
|
||
|
let vel = velocity(in: view)
|
||
|
switch direction {
|
||
|
case .horizontal where fabs(vel.y) > fabs(vel.x):
|
||
|
state = .cancelled
|
||
|
case .vertical where fabs(vel.x) > fabs(vel.y):
|
||
|
state = .cancelled
|
||
|
default:
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|