2

Can a UIPanGestureRecognizer be added while the user is touching and immediately start recognizing the pan gesture? I can only get it to work if I lift up my finger, touch again and start dragging.

From another answer, I've tried to subclass UIPanGestureRecognizer and override the touch event:

import UIKit.UIGestureRecognizerSubclass

class InstantPanGestureRecognizer: UIPanGestureRecognizer {

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent) {
     if (self.state == UIGestureRecognizer.State.began) { return }
            super.touchesBegan(touches, with: event)
            self.state = UIGestureRecognizer.State.began
     }

}

This doesn't solve my problem though, probably because they already had their UIPanGestureRecognizer added, and I want to add mine while the user is already touching the screen and have it work at that point.

I'm switching between adding swipe and pan gestures depending on where the user the is interacting on an image. The require(tofail:UIGestureRecognizer) function hasn't worked for me.

RN92
  • 1,380
  • 1
  • 13
  • 32
Chewie The Chorkie
  • 4,896
  • 9
  • 46
  • 90
  • “Can a UIPanGestureRecognizer be added while the user is touching and immediately start recognizing the pan gesture?” No, that’s too late. The fate of this touch has already been determined. – matt Apr 01 '19 at 22:18
  • Really? It seems as though you'd be able to modify and trigger these events programmatically without actually touching the screen. In fact, I can call touchesBegan on the pan gesture like: panGestureRecognizer.touchesBegan(touch as! Set, with: e) – Chewie The Chorkie Apr 01 '19 at 22:20
  • 1
    You can do a lot of things that will cause havoc. :) – matt Apr 01 '19 at 22:23
  • You don't need `UIPanGestureRecognizer`. And what are you trying to relocate? – El Tomato Apr 01 '19 at 23:31
  • Thanks @ElTomato. I'm using the translation value of UIPanGestureRecognizer to change the size of a border on a photo when it's dragged towards the center. This is updated in real time by grabbing an image from video from the camera and adding CIFilters and making a new updated CIImage in a MTKView. – Chewie The Chorkie Apr 02 '19 at 14:31

0 Answers0