当点击UITextView时,我希望它作为第一个响应者继续工作,但我还需要触发其他事件。 UITapGestureRecognizer在UITextView不是第一响应者之前工作良好,但在它聚焦后,无法再识别该点击。
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
}
答案 0 :(得分:4)
在ViewDidLoad()
方法中使用以下代码,并确保包含
[yourTextView setUserInteractionEnabled:YES]
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:SEL(textViewTapped:)];
[gestureRecognizer setNumberOfTapsRequired:1];
[yourTextView addGestureRecognizer:gestureRecognizer];`
答案 1 :(得分:0)
您应该在手势识别器代理上实现以下方法:
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer*)otherGestureRecognizer {
return YES;
}