Resolved UITextView and Event Handling/Gesture recognizers

Discussion in 'iOS Programming' started by brontosaurus, Jun 29, 2012.

  1. brontosaurus, Jun 29, 2012
    Last edited: Jun 29, 2012

    brontosaurus macrumors newbie

    Joined:
    Mar 1, 2012
    Location:
    Yakima, WA (no where USA)
    #1
    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.
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    You've tagged this thread as Resolved. Is it? Seems unclear whether you've solved this problem or not.
     
  3. daver969 macrumors newbie

    Joined:
    May 11, 2004
    Location:
    Monterey, CA
    #3
    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.
     

Share This Page