Delaystouchesended: The document explains that when the gesture reader identifies a gesture, the touch in the uitouchphaseended phase will be delayed and sent to the hit-test view. After the gesture recognition is successful, send the original End message to hit-test view cancel when the gesture recognition fails. This example is provided to identify the uitapgesturerecognizer object in the double-click operation. Its numberoftapsrequired is set to 2. If the delaystouchesended is no, the call sequence in the hit-test view is
Touchesbegan: withevent :,
Touchesended: withevent :,
Touchesbegan: withevent :,
And touchescancelled: withevent:
If delaystouchesended is yes, the call sequence is:
Touchesbegan: withevent :,
Touchesbegan: withevent :,
Touchescancelled: withevent :,
Touchescancelled: withevent:
However, this is not the case in actual tests. The actual test result is that if delaystouchesended is no, the call sequence is:
Touchesbegan: withevent :,
Touchesended: withevent :,
Tapgesturerecognizer detected double-click
If delaystouchesended is yes, the call sequence is:
Touchesbegan: withevent :,
Touchesended: withevent :,
Tapgesturerecognizer detected double-click
Touchescancelled: withevent:
This problem has not been clarified yet!
3. Relationships between multiple gesture recognizerYou can bind multiple gesture recognizer to a view. By default, touch events in the touch sequence are transmitted in uncertain order in each gesture recognizer, until the event is finally sent to hit-test view (if it is not identified and intercepted by gesture recognizer ). The relationships between multiple gesture recognizer can also be customized as needed, mainly including the following actions
1. If one of the gesture recognizer fails, the other gesture recognizer can analyze the event.
For example, two gesture recognizers are used to identify the click and double-click operations, singletapgesture and doubletapgesture respectively. By default, When you click an operation, singletapgesture identifies a click operation. doubletapgesture also identifies a double-click action, but our intention is, this is just a double-click operation. In this case, we can use the identifier of uigesturerecognizer: Method to enable singletapgesture to analyze events when doubletapgesture identifies and identifies events. If doubletapgesture identifies double-click events, singletapgesture will not take any action.
[Singletapgesture requiregesturerecognizertofail: doubletapgesture];
Note that, in this case, if you perform a click operation, it takes a delay (that is, doubletapgesture failed to identify), singletapgesture will recognize the click action and perform click processing, during this period of time, there was almost no impact on actual use.
2. Precisely control whether gesture recognizer responds to an event or event sequence.
There are two optional methods in the uigesturerecognizerdelegate protocol to control whether gesture recognizer needs to recognize certain events
- Gesturerecognizershouldbegin:
This method is called when the gesture recognizer view is transferred out of the uigesturerecognizerstatepossible state. If no is returned, the method is switched to uigesturerecognizerstatefailed. If yes is returned, the touch sequence is recognized)
- Gesturerecognizer: shouldreceivetouch:
This method is called before the touchesbegan: withevent: Method of gesture recognizer when a touch event occurs in the window object. If no is returned, gesture recognizer will not see this touch event. (Yes by default ).
In addition, there are two rewrite methods in the uigesturerecognizer class to complete the same functions as the delegate method.
-(Bool) canpreventgesturerecognizer :( uigesturerecognizer *) preventedgesturerecognizer;
-(Bool) canbepreventedbygesturerecognizer :( uigesturerecognizer *) preventinggesturerecognizer;
3. Multiple gesture identifiers can be recognized togetherBy default, two gesture recognizers do not recognize their gestures at the same time, but you can implement the uigesturerecognizerdelegate protocol in
Gesturerecognizer: shouldrecognizesimultaneouslywithgesturerecognizer: method to control it. This method is called when either of the two gesture recognizers blocks Another touch event. If yes is returned, both gesture recognizers can recognize the event at the same time. If no is returned, it is not guaranteed that two gesture recognizers cannot be recognized at the same time, because this method of another gesture recognizer may return YES. That is to say, if either of the two gesture recognizers delegate Methods returns Yes, both of them can be recognized at the same time. Only when both return no is mutually exclusive. By default, no is returned.
In this example, if you want to detect all the touch events on the window, you can associate gesture recognizer with the window. By default, if the gesture is recognized by the window, the gesture recognizer in the sub-view becomes invalid, while the goal of gesture recognizer on the window is to monitor all events, but not to handle these events, the processing of specific events also requires various gesture recognizer in the subview to process the events. In this way, we can bind the gesture recognizer delegate method on the window so that gesturerecognizer: Yes is returned.
-(Bool) gesturerecognizer :( uigesturerecognizer *) gesturerecognizer restart :( uigesturerecognizer *) othergesturerecognizer {return yes ;}
Iv. Similar uiscrollview Behavior
The scroll view does not have a scroll bar. When there is a touch behavior on the scroll view, it must identify whether the scroll view itself is a child view of its content. To customize how scrollview handles this situation, see the following attributes and methods of the uiscrollview class.
-Touchesshouldbegin: withevent: incontentview:
-Touchesshouldcancelincontentview:
Cancancancelcontenttouches
Delayscontenttouches
reference:
event handling guide for iOS-gesture recognizers
uigesturerecognizer class reference
define Protocol Reference
detecting all touches in an app
uiscrollview class reference
how to recognize swipe gesture in uiscrollview
uigesturerecognizer blocks subview for handling touch events
uibutton touch is delayed when in uiscrollview
Why is scrolling A uitableview much more responsive than scrolling A uiscrollview?
How to cancel touches exactly like uiscrollview?