iOS 【手势获取cell位置】【点击cell获取indexpath】

如何获取手指点击的cell位置:

1,首先创建一个长按(可以是点击或者其他手势)

UILongPressGestureRecognizer * longgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]

2,在方法中进行实现

- (void)handleLongPress:(UILongPressGestureRecognizer *)recognizer

{

//假如是开始点击

if (recognizer.state == UIGestureRecognizerStateBegan )

  {  //获取当前点击的indexpath

    CGPoint location = [recognizer locationInView:self.tableView];

          NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];

    //根据index算出rect

    CGRect rectInTableView = [self.tableView rectForRowAtIndexPath:cellIndexPath];

    CGRect rectInSuperview = [self.tableView convertRect:rectInTableView toView:[self.tableView superview]];

    //这里的rectInSuperview就是你当前手指所点的cell的位置

  }

}

posted @ 2017-05-09 16:32  OC大人  阅读(1381)  评论(0编辑  收藏  举报