Transferred from: http://blog.csdn.net/longzs/article/details/7457108
In iOS development, you need to use a finger for different actions, with the finger click for example: Divided into single-finger click, Single-Finger multi-click, multi-finger click, multi-finger multi-hit. For these events to be handled differently, due to the use of the system's own method by judging touches is not easy to handle, and there will be conflicts between events.
Next, the requirement code for implementing this feature with UITapGestureRecognizer gestures is as follows:
The Viewdidload method in VIEWCONTROLLER.M:
1: //single finger click
2:
3: Action: @selector (handlesinglefingerevent:)];
4: //Hand index
5: number of//tap
6: singlefingerone. delegate = self;
7:
8: //single-finger double-tap
9:
: Action: @selector (handlesinglefingerevent:)];
One: singlefingertwo.numberoftouchesrequired = 1;
: singlefingertwo.numberoftapsrequired = 2;
: singlefingertwo. delegate = self;
14:
: //double-finger click
16:
: Action: @selector (handledoublefingerevent:)];
: doublefingerone.numberoftouchesrequired = 2;
: doublefingerone.numberoftapsrequired = 1;
: Doublefingerone. delegate = self;
21st:
22:
: Action: @selector (handledoublefingerevent:)];
: doublefingertwo.numberoftouchesrequired = 2;
: doublefingertwo.numberoftapsrequired = 2;
A: doublefingertwo. delegate = self;
27:
: //If you do not add the following, when a single-finger double-click, the first call to single-hit processing, and then call a single-finger double-hit processing
£ º [singlefingerone Requiregesturerecognizertofail:singlefingertwo];
the same with two fingers
: [Doublefingerone requiregesturerecognizertofail:doublefingertwo];
32:
£ º [Self.view Addgesturerecognizer:singlefingerone];
: [Self.view addgesturerecognizer:singlefingertwo];
: [Self.view Addgesturerecognizer:doublefingerone];
£ º [Self.view Addgesturerecognizer:doublefingertwo];
37:
: [Singlefingerone release];
: [Singlefingertwo release];
Max: [Doublefingerone release];
In: [Doublefingertwo release];
Methods of handling events, code:
1: //handling single-finger events
2: -(void) Handlesinglefingerevent: (UITapGestureRecognizer *) Sender
3: {
4: if (sender.numberoftapsrequired = = 1) {
5: //single finger click
6: NSLog (@ "single finger click");
7: }if (sender.numberoftapsrequired = = 2) {
8: //single-finger double-tap
9: NSLog (@ "single finger double click");
Ten: }
One: }
: //Handle two-finger events
: -(void) Handledoublefingerevent: (UITapGestureRecognizer *) Sender
: {
: if (sender.numberoftapsrequired = = 1) {
+ //double finger Click
: NSLog (@ "double finger Click");
: }if (sender.numberoftapsrequired = = 2) {
+ //double-fingered double-tap
: NSLog (@ "double-finger double-click");
: }
: }
Copy the code into your project and you can use it, as there is already a detailed explanation in the code that is not repeated here.
The code only lists the single and double fingers for the processing of click or multi-hit, the same as multi-fingered operation needs to modify the Numberoftouchesrequired property, the number of clicks need to modify the Numberoftapsrequired property.
Similar processing is used for other gestures such as uiswipegesturerecognizer,uilongpressgesturerecognizer,uilongpressgesturerecognizer operations.
iOS uitapgesturerecognizer single-finger click, Single-Finger multi-click, multi-fingered, multi-finger multi-click event action