Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

brontosaurus

macrumors newbie
Original poster
Mar 1, 2012
11
0
Yakima, WA (no where USA)
I have a UITextView that takes up the entire screen (so it's the hit-test view I guess). When I don't want the user to edit the text view, I set its editable property to NO. This still allows the user to scroll the text view (I want scrolling!).

textView.editable = NO;

When the text view is un-editable, I add a tap gesture recognizer to a parent view to detect double taps.
Code:
self.doubleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(recognizedDoubleTap:)];
self.doubleTapRecognizer.numberOfTapsRequired = 2;
[self.view addGestureRecognizer:self.doubleTapRecognizer];

However, the parent view never seems to receive a double tap gesture. It seems like the text view and/or its 9 gesture recognizers is gobbling up all the touch events even when it's un-editable (I logged the names of a text view's 9 gesture recognizers: my favorite is UITapAndAHalfRecognizer).

So I have iterated through the text view's 9 gesture recognizers and regulated the delivery of touches so that the parent view could receive touches:
Code:
        NSArray *gestures = [textView gestureRecognizers];
        
        for (int i = 0; i < 9; i++) {
            [[gestures objectAtIndex:i] setCancelsTouchesInView:NO];
            [[gestures objectAtIndex:i] setDelaysTouchesEnded:NO];
        }

Unfortunately, the parent view still doesn't receive double taps. Any suggestions? Keep in mind that I want my text view to scroll. Therefore, I don't want to set the text view's userInteractionEnabled property to NO.
 
Last edited:

daver969

macrumors newbie
May 11, 2004
18
0
Monterey, CA
UITextView built in gesture recognizers

I have found that the built-in recognizers for UITextViews (at least the ones that handle the selection of text) are remarkably hard to kill because they frequently reset themselves. I tried the generally recommended method for overriding them: iterate through the UITextView's gestureRecognizers array and disable any that conflict with my GR (I wanted to define my own action for a double tap). Seems simple enough, the problem is that the UITextView appears to refresh its gesture recognizers every time they're used. So I managed to get it to work the first time, but then the UITextView refreshes it's own GR's. Perhaps this is because my method for the 2-tap gesture selects all the text in the UITextView. Doing this brings up the little segmented button with different options (copy, cut, etc.), and then when this is dismissed it wants to reset all its GRs. The thing is, it doesn't remove mine, it just ignores it.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.