如何获取手指点击的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的位置
}
}
时间: 2024-10-05 04:09:17