简体   繁体   中英

How to prefer tap gesture over draw gesture?

In my view I'm overriding all the "touches*" methods to let the user draw on the screen. I'm recording the locations. In addition I have two gesture recognizers on my view to detect single tap and double tap. If I now move my finger just a little bit and short enough, I will be recording a small "draw" gesture. However when raising the finger, an additional tap gesture will be triggered. By trial and error I could possibly figure out a minimum time and movement threshold but I'm sure there are smarter ways? I need to know after how much movement and/or it is save to assume that no tap gesture will trigger.

You can avoid tap gestures. Instead of that you can recognize taps in touch events itself.

- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
    if(touches.count == 1)
    {  

       if([[touches anyObject] tapCount] == 1)
       {
       // Do the action here for single tap
       }

       else if([[touches anyObject] tapCount] == 2)
       {
       // Do the action here for double tap
       }
    }
}

And you have to set a global bool variable for check whether user moved the finger on the screen.

BOOL _isMoved;

And make it TRUE in the touch move event

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

    _isMoved = YES;
}

Before recording the track, you check whether this flag is TRUE or not? And also dont forget to make the flag to FALSE after saving the track

Hope this will help you :)

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