简体   繁体   中英

iOS: UIVIew touches delegates vs single tap recognizer

I am handling Touches delegates and UITapGestureRecognizer for single tap. Following are the methods. When I single tap on my View, I get three events in order of TouchesBegan , SingleTap , and TouchesEnded . Is there anyway to stop TouchesEnded event when I have SingleTap detected? Basicaaly I don't want to perform tasks in TouchesEnded if TouchesMoved didn't happen. I have done this using failTouchEnded BOOL variable in SingleTap and checking it in TouchesEnded but not sure if it is a good idea!

   - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    }

    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
          failTouchEnded = NO;
    }

    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
          if(failTouchEnded) return;

    }

    - (void)GestureView:(GestureView*)view handleSignleTap:(UITapGestureRecognizer*)recognizer {
          failTouchEnded = YES;
    }

gestureRecognizer has a property cancelsTouchesInView. if it is YES (which is default) cancels the touches if the gesture recognizer recognizes the gesture. So you will get a touches canceled instead of touches ended. You should set delaysTouchesEnded to YES too if it is not YES

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM