mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
39 lines
952 B
Swift
39 lines
952 B
Swift
//
|
|
// 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
|
|
}
|
|
}
|
|
}
|
|
}
|