当 UITextView 被点击时,我希望它继续作为第一响应者工作,但我还需要触发其他事件。在 UITextView 不是第一响应者之前,UITapGestureRecognizer 工作得很好,但是在它聚焦之后,不再识别点击。

  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
  }

最佳答案

ViewDidLoad() 方法中使用以下代码,并确保包含

[yourTextView setUserInteractionEnabled:YES]

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

 [gestureRecognizer setNumberOfTapsRequired:1];
 [yourTextView addGestureRecognizer:gestureRecognizer];`

关于objective-c - 在文本 View 成为第一响应者后如何识别点击?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12631565/

10-09 18:33