UITapGestureRecognizer

UITapGestureRecognizer

我在用 :

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
                               initWithTarget:self
                               action:@selector(dismissKeyboard:)];
[self.view addGestureRecognizer:tap];

为了从UITextField中的其他任何地方单击时关闭键盘。

但是,在我看来,我有UITableView,并且必须检测何时单击UITableView的行。
由于UITapGestureRecognizer,未调用我的didSelectRowAtIndexPath函数。有什么方法可以检测单击的对象是否为UITableViewCell?

最佳答案

您可以从以下途径获得“手势” Activity

- (BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch

您会检测到手势的触摸,因此在逻辑上就像下面这样:
- (BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if ([touch.view isKindOfClass:[UITextFiled class]])
    {
        return FALSE;
    }
    else
    {

     // here is remove keyBoard code
        return TRUE;
    }
}

关于ios - 如何检测UITapGestureRecognizer的单击 View ?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24137737/

10-12 00:16