How to recognize oneTap/doubleTap at moment?

前端 未结 7 736
独厮守ぢ
独厮守ぢ 2020-12-05 05:51

I Know filtering oneTap/doubleTap using a Apple API. code are follows.

UITapGestureRecognizer *doubleTapGestureRecognizer = [[UITapGestureRecognizer alloc]
          


        
相关标签:
7条回答
  • 2020-12-05 06:54

    Here's a simpler answer to this problem, if you already have an action attached to the button or view. First, change the IBAction so that it includes the UIEvent (don't forget to reconnect it to your button or view in the Storyboard):

    -(IBAction)buttonAction:(id)sender forEvent:(UIEvent*)event
    

    Next, in your you can capture the touches from the event, and then easily test for the tap count:

    -(IBAction)buttonAction:(id)sender forEvent:(UIEvent*)event {
    
         UITouch* firstTouch = nil;
         if ((nil != ((firstTouch = event.allTouches.allObjects.firstObject)))
             && (2 == firstTouch.tapCount))
         {
             // do something for double-tap
         } else {
             // do something for single-tap
         }
    }
    

    You can extend this solution with other cases for different event parameters, such as long taps.

    0 讨论(0)
提交回复
热议问题