4

When the UITextView is tapped, I want it to stay working as the first responder but I need also to fire other events. The UITapGestureRecognizer works well before the UITextView is not first responder, but after it gets focused the tap is not recognized any more.

  UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapRecognized:)];
  singleTap.numberOfTapsRequired = 1;
  [txtView addGestureRecognizer:singleTap];
  [singleTap release];

  -(IBAction)singleTapRecognized:(id)sender
  {
     //Does not enter here with a tap after txtView is first responder
  }
Laureano Bonilla
  • 335
  • 3
  • 18

2 Answers2

4

Use the following code in ViewDidLoad() method, and make sure to include

[yourTextView setUserInteractionEnabled:YES] 

UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:SEL(textViewTapped:)];

 [gestureRecognizer setNumberOfTapsRequired:1];  
 [yourTextView addGestureRecognizer:gestureRecognizer];`
Sathyajith Bhat
  • 21,321
  • 22
  • 95
  • 134
iSpark
  • 952
  • 7
  • 18
  • The creation of the gesture recognizer in my code is done in the viewdidload. I can't see difference between my code and this one. I also tried setting the interaction enabled and it makes no difference. I think UITextView's interaction enabled is true by default. – Laureano Bonilla Sep 28 '12 at 17:00
0

You should implement the following method on your gesture recognizer delegate:

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer*)otherGestureRecognizer {
    return YES;  
}
Dmytro Hutsuliak
  • 1,741
  • 4
  • 21
  • 37