Similar to this answer I gave to a similar question, but with the caveat that I've only used this on iOS 10, you can do this by extending UITextView
with a custom class and overriding addGestureRecognizer:
.
Keeping track of the singleTap just acts as a sentinel for adding the two finger tap, since the UITextView
is constantly adding and dropping gestures:
@interface MyCustomTextView ()
@property (weak, nonatomic) UITapGestureRecognizer *singleTap;
@end
@implementation MyCustomTextView
/**
* this will fire when the text view is tapped with two fingers
*
* @param tgr
*/
- (void)_handleTwoTouches:(UITapGestureRecognizer *)tgr
{
// ADD CODE HERE
}
- (void)addGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
{
[super addGestureRecognizer:gestureRecognizer];
if ([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) {
UITapGestureRecognizer *tgr = (UITapGestureRecognizer *)gestureRecognizer;
if ([tgr numberOfTapsRequired] == 1 && [tgr numberOfTouchesRequired] == 1) {
if (!self.singleTap) {
self.singleTap = tgr;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(_handleTwoTouches:)];
tap.numberOfTapsRequired = 1;
tap.numberOfTouchesRequired = 2;
[super addGestureRecognizer:tap];
}
}
}
}
@end