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.
session-ios/SignalMessaging/Views/ImageEditor/ImageEditorPanGestureRecogn...

53 lines
1.3 KiB
Swift

//
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
//
import UIKit
// This GR:
//
// * Tries to fail quickly to avoid conflicts with other GRs, especially pans/swipes.
// * Captures a bunch of useful "pan state" that makes using this GR much easier
// than UIPanGestureRecognizer.
public class ImageEditorPanGestureRecognizer: UIPanGestureRecognizer {
public weak var referenceView: UIView?
// Capture the location history of this gesture.
public var locations = [CGPoint]()
public var locationStart: CGPoint? {
return locations.first
}
// MARK: - Touch Handling
@objc
public override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent) {
super.touchesBegan(touches, with: event)
guard let referenceView = referenceView else {
owsFailDebug("Missing view")
return
}
locations.append(location(in: referenceView))
}
@objc
public override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent) {
super.touchesMoved(touches, with: event)
guard let referenceView = referenceView else {
owsFailDebug("Missing view")
return
}
locations.append(location(in: referenceView))
}
public override func reset() {
super.reset()
locations.removeAll()
}
}