有没有办法从轻敲的位置获得一个cgpoint而不必使用触摸方法,如触摸开始或触摸移动?

时间:2014-07-03 15:24:04

标签: ios objective-c

有没有办法从轻敲的位置获取cgpoint,而不必使用触摸方法,如触摸开始或触摸移动?我问,因为我有一个内置UITableView的视图,并且由于某种原因,触摸方法似乎没有在表视图中工作。

1 个答案:

答案 0 :(得分:2)

您可以使用 UITapGestureRecognizer

你应该把它放在初始化方法中:

UITapGestureRecognizer * = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRecognized:)];
[theTargetView addGestureRecognizer:tapRecognizer];//theTargetView could also be self.view

目标类中的其他地方:

- (void)tapRecognized:(UITapGestureRecognizer *)recognizer
{
    if(recognizer.state == UIGestureRecognizerStateRecognized)
    {
        CGPoint point = [recognizer locationInView:recognizer.view];
        //your coordinates ;)
    }
}