iOS long-press gesture two-way call resolution

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.