mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-02-05 18:58:51 +00:00
Fix gestures
This commit is contained in:
@@ -231,6 +231,16 @@ private func layoutMetricsForScreenSize(size: CGSize, orientation: UIInterfaceOr
|
||||
}
|
||||
|
||||
public final class WindowKeyboardGestureRecognizerDelegate: NSObject, UIGestureRecognizerDelegate {
|
||||
public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
|
||||
if let view = gestureRecognizer.view {
|
||||
let location = touch.location(in: gestureRecognizer.view)
|
||||
if location.y > view.bounds.height - 44.0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
|
||||
return true
|
||||
}
|
||||
@@ -1299,7 +1309,7 @@ public class Window1 {
|
||||
}
|
||||
}
|
||||
|
||||
@objc func panGesture(_ recognizer: UIPanGestureRecognizer) {
|
||||
@objc func panGesture(_ recognizer: WindowPanRecognizer) {
|
||||
switch recognizer.state {
|
||||
case .began:
|
||||
self.panGestureBegan(location: recognizer.location(in: recognizer.view))
|
||||
|
||||
@@ -7,6 +7,7 @@ public final class WindowPanRecognizer: UIGestureRecognizer {
|
||||
public var ended: ((CGPoint, CGPoint?) -> Void)?
|
||||
|
||||
private var previousPoints: [(CGPoint, Double)] = []
|
||||
private var previousVelocity: CGFloat = 0.0
|
||||
|
||||
override public func reset() {
|
||||
super.reset()
|
||||
@@ -45,6 +46,11 @@ public final class WindowPanRecognizer: UIGestureRecognizer {
|
||||
}
|
||||
}
|
||||
|
||||
func velocity(in view: UIView?) -> CGPoint {
|
||||
let point = CGPoint(x: 0.0, y: self.previousVelocity)
|
||||
return self.view?.convert(point, to: view) ?? .zero
|
||||
}
|
||||
|
||||
override public func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent) {
|
||||
super.touchesBegan(touches, with: event)
|
||||
|
||||
@@ -68,9 +74,12 @@ public final class WindowPanRecognizer: UIGestureRecognizer {
|
||||
override public func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent) {
|
||||
super.touchesEnded(touches, with: event)
|
||||
|
||||
self.state = .ended
|
||||
|
||||
if let touch = touches.first {
|
||||
let location = touch.location(in: self.view)
|
||||
self.addPoint(location)
|
||||
self.previousVelocity = self.estimateVerticalVelocity()
|
||||
self.ended?(location, CGPoint(x: 0.0, y: self.estimateVerticalVelocity()))
|
||||
}
|
||||
}
|
||||
@@ -78,6 +87,8 @@ public final class WindowPanRecognizer: UIGestureRecognizer {
|
||||
override public func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent) {
|
||||
super.touchesCancelled(touches, with: event)
|
||||
|
||||
self.state = .cancelled
|
||||
|
||||
if let touch = touches.first {
|
||||
self.ended?(touch.location(in: self.view), nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user