Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add double tap gesture to UITextView

currently I want to let UITextView to have a double tap gesture. It seems UITableView has its own double tap gesture, when we double tapped, some text will be selected. So I want to remove this default double tap gesture to my own gesture recognizer. I tried many methods, and all failed. It seems there's no way to remove the default recognizer of UITextView. I also want to add a transparent view on this UITextView to do double tap event, but this subview will block other gestures on UITextView. Is there some method to add double tap gesture recognizer to UITextView? I really hope there will be a work around.

I am still expecting a work around of iOS5 :)

like image 350
Charlesjean Avatar asked Dec 04 '22 13:12

Charlesjean


1 Answers

There are a number of other gesture recognizers attached to a text view. Since you don't seem to need them. You can remove them.

myTextView.gestureRecognizers = nil;

before adding your double tap recognizer. It works.

then you can add

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(mySelector)];
tapRecognizer.numberOfTapsRequired = 2;
tapRecognizer.numberOfTouchesRequired = 1;
[myTextView addGestureRecognizer:tapRecognizer];
like image 77
Mohammad Rabi Avatar answered Dec 27 '22 21:12

Mohammad Rabi