I have a iOS game and during loading screens any touches the user does seem to be buffered up, so once the loading it done (it can take a few seconds), I get the touch events.
Is there way for me to discard all touches?
Ok this is a really old question but for anyone stumbling upon this can simply follow either of the below two approaches:
Approach 1.
DiscardTouchView.addGestureRecognizer(UITapGestureRecognizer())
Basically adding an empty gesture. So on tapping that view nothing happens.
Approach 2.
In this case you don't add empty gesture recognizer to the view. In case DiscardTouchView is a subview of SomeParentView which has a UIGestureRecognizer object, you can get that object and ignore it.
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let tappedView = touches.first?.view else { return }
if(tappedView == DiscardTouchView) {
guard let recognizer = touches.first?.gestureRecognizers?.first else { return }
recognizer.ignore(touches.first!, for: event!)
}
}
Setting userInteractionEnabled to false actually passes the touch event from subview to superview. It doesn't discard the touch event.
Setting userInteractionEnabled to true for a simple UIView does the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With