Can you make the touch event cancel after touching Began?

Given the specific state of one of my UIViews, I would like it to respond to touchsBegan and then cancel any further movd / ended touches that continue from this particular touchBegan event.

Basically, I have a subclass of UIView alone, and if it touched, I would like to drop some other UIViews out of the way ... then the next time it touches the responder chain, you can respond normally to touchMoved / Ended ...

yes, I could check this state in touchhesMoved / Ended, but I wonder if there is a way to just subvert this touch event in the middle of the phase.

+5
source share
5 answers
    let fakeTouch:Set<NSObject> = [UITouch()]
    let event     = UIEvent()

    self.touchesEnded(fakeTouch, withEvent: event)
+1

, , .

- . , . .

[self resignFirstResponder];
0

, , , , ==

UITouch *anyTouch = [touches anyObject];
if (anyTouch != self.lastTouch)
     return;

, UITouch UIView ( lastTouch), , /. , , .

, .

0

,

Xcode 9, Swift 4 iOS 11,

self.resignFirstResponder()
self.touchesEnded(touches, with: event)

:

let superview = self.superview
self.removeFromSuperview()
superview?.addSubview(self)

. Storyboard.

, , , subviews. superview.subviews

0

, UIScrollView . , . , .

-2
source

All Articles