UILongPressGestureRecognizer和UITableview

时间:2013-07-17 10:02:22

标签: objective-c uitableview scroll uigesturerecognizer

我有一个UITableView,每行UIImage添加了UILongPressGestureRecognizer。现在我遇到了问题,当触摸imageView时,会执行gestureRecognizer的代码。但是当我向上/向下移动手指时,表格视图不会滚动。

这很清楚,因为touch仍然在gestureRecognizer中。

我有没有办法让我的gestureRecognizer中的tableView滚动?也就是说,当我在gestureRecognizer中并且手指向上移动时,我调用tableView滚动方法?

1 个答案:

答案 0 :(得分:1)

我认为它可能对您有用

     UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
                                                                   initWithTarget:self
                                                                   action:@selector(handleLongPress:)];
    longPress.minimumPressDuration = 1.0;
    [cell addGestureRecognizer:longPress];

  -  (void)handleLongPress:(UILongPressGestureRecognizer*)sender {
        CGPoint location = [sender locationInView:yourtableviewobj];
        //Get the corresponding index path within the table view
        NSIndexPath *indexPath = [self.tablechat indexPathForRowAtPoint:location];
        if (sender.state == UIGestureRecognizerStateEnded) {
      }
        else if (sender.state == UIGestureRecognizerStateBegan){
       }
    }