Delaystouchesended, the explanation on the document is that when the gesture recognizer recognizes gestures, the touch of the uitouchphaseended phase is delayed to Hit-test view, and after the gesture recognition is successful, it is sent to Hit-test The view cancel message, when gesture recognition fails, sends the original end message. It gives an example of the UITapGestureRecognizer object that identifies the double-click operation, whose numberoftapsrequired is set to 2, and if delaystouchesended is no when the user makes a double-click operation, The call order in Hit-test view is listed as
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:
But when I was actually testing, that was not the case, the result of the actual test is that if delaystouchesended is no, then the call sequence is:
Touchesbegan:withevent:,
Touchesended:withevent:,
Tapgesturerecognizer detected a double-click
If delaystouchesended is yes, the call sequence is:
Touchesbegan:withevent:,
Touchesended:withevent:,
Tapgesturerecognizer detected a double-click
Touchescancelled:withevent:
The problem is not clear!
Three. Relationships between multiple gesture recognizerMultiple gesture recognizer can be bound on a view, and by default touch events in the touch sequence are passed in an indeterminate order across gesture recognizer until the event is eventually sent to Hit-test View (if the middle is not identified and intercepted by gesture recognizer). The relationships between multiple gesture recognizer can also be tailored to your needs, mainly in the following types of behaviors
1. In case one of the gesture recognizer fails, the other gesture recognizer can parse the event.To identify both the click action and the double-click operation as an example, two gesture recognizers are used to identify the click and double clicks, respectively, Singletapgesture and Doubletapgesture. By default, when a user clicks, Singletapgesture recognizes a single click, and Doubletapgesture also recognizes a double-click action, but our intention is that this is just a double-click operation. In this case we can use Uigesturerecognizer's requiregesturerecognizertofail: method to enable Singletapgesture to parse an event when doubletapgesture recognition is recognized, and if Doubletapgesture identifies a double-click event, Singletapgesture will not have any action.
[singleTapGesture requireGestureRecognizerToFail:doubleTapGesture];
It is important to note that, in this case, if a user clicks a delay (that is, the doubletapgesture recognition fails), Singletapgesture will recognize the click action and click Processing, which is a lot of time and has little effect on actual use.
2. Precisely control whether the gesture recognizer responds to an event or sequence of events.There are two optional methods in the Uigesturerecognizerdelegate protocol to control whether gesture recognizer need to identify certain events
- Gesturerecognizershouldbegin:
This method is called when the gesture recognizer view goes out of the uigesturerecognizerstatepossible state, and if no is returned, it is converted to uigesturerecognizerstatefailed; If yes is returned, the touch sequence continues to be recognized. (Yes by default)
- Gesturerecognizer:shouldreceivetouch:
This method is called before the Window object calls the Touchesbegan:withevent: method of the gesture recognizer when a touch event occurs, and if no is returned, gesture recognizer will not see this touch event. (yes by default).
In addition, there are two methods that can be overridden in the Uigesturerecognizer class to accomplish the same functionality as in the delegate method
-(BOOL) Canpreventgesturerecognizer: (Uigesturerecognizer *) Preventedgesturerecognizer;
-(BOOL) Canbepreventedbygesturerecognizer: (Uigesturerecognizer *) Preventinggesturerecognizer;
3. Allow multiple gesture recognizers to identify togetherBy default, two gesture recognizers do not recognize their gestures at the same time, but you can implement the Uigesturerecognizerdelegate protocol
Gesturerecognizer:shouldrecognizesimultaneouslywithgesturerecognizer: Method to control it. This method is called when any one of these two gesture recognizers will block another touch event, and if yes is returned, two gesture recognizers can be identified simultaneously, and if no is returned, two gesture is not guaranteed Recognizers must not be recognized at the same time, because this method of another gesture recognizer may return yes. That is to say, the delegate method of the two gesture recognizers only returns Yes if any one, then the two can be identified at the same time, only two return no, is mutually exclusive. By default, no is returned.
For example, if you want to detect all touch events on a window, you can associate the gesture recognizer to the window, by default if the gesture is recognized by the window, the gesture recognizer in the child view is invalidated. The purpose of our gesture recognizer on window is simply to monitor all events, but not to deal with them, and the handling of the events requires each gesture recognizer in the sub-view to be processed, This allows us to implement the delegate method of binding gesture recognizer to the window, so that the Gesturerecognizer: Shouldrecognizesimultaneouslywithgesturerecognizer: Returns YES.
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { return YES;}
Four. Similar behavior of UiscrollviewScroll view does not have a scroll bar, and when there is touch behavior on scroll view, it recognizes that the purpose of the touch behavior is to scroll view itself or its content sub-view. Customizing ScrollView How to handle this situation, see the following properties and methods of the Uiscrollview class.
–touchesshouldbegin:withevent:incontentview:
–touchesshouldcancelincontentview:
Cancancelcontenttouches
Delayscontenttouches
Reference:
Event Handling Guide for Ios–gesture recognizers
Uigesturerecognizer Class Reference
Uigesturerecognizerdelegate 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 if in Uiscrollview
Why are scrolling a uitableview much more responsive than scrolling a uiscrollview?
How to cancel touches exactly like Uiscrollview?