Since there was not a very detailed study of long-press gestures, it was used today to find that a long-press gesture invokes two response events.
The main reason is that the long press gesture UIGestureRecognizerStateBegan will UIGestureRecognizerStateEnded call the response function separately in the and state
In response to the event, you need to increase the gesture state of judgment, according to the specific application situation in the corresponding State to perform the operation.
typedefNs_enum (Nsinteger,Uigesturerecognizerstate) {Uigesturerecognizerstatepossible,The recognizer have not yet recognized it gesture, but could be evaluating touch events. The default stateUigesturerecognizerstatebegan,The recognizer has received touches recognized as the gesture. The action method is called at the next turn of the run loopUigesturerecognizerstatechanged,The recognizer have received touches recognized as a change to the gesture. The action method is called at the next turn of the run loopUigesturerecognizerstateended,The recognizer has received touches recognized as the end of the gesture. The action method is called at the next turn of the run loop and the recognizer would be the reset to Uigesturerecognizers TatepossibleUigesturerecognizerstatecancelled,The recognizer have received touches resulting in the cancellation of the gesture. The action method is called at the next turn of the run loop. The recognizer would be a reset to uigesturerecognizerstatepossibleuigesturerecognizerstatefailed,//the recognizer has Received a touch sequence that can is recognized as the gesture. The action method won't be called and the recognizer would be reset to Uigesturerecognizerstatepossible//discrete gestures–gesture recognizers" recognize a discrete event but does not report changes (for Exampl E, a tap) do not transition through the began and Changed states and can not fail or be cancelled uigesturerecognizerstaterecognized =uigesturerecognizerstateended//The recognizer has received touches recognized as the gesture. The action method is called at the next turn of the run loop and the recognizer would be the reset to Uigesturerecognizers Tatepossible};
if (longPressGesture.state == UIGestureRecognizerStateBegan) { // do something}else if (longPressGesture.state == UIGestureRecognizerStateEnded){ // do something}
iOS long-press gesture two-way call resolution