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的位置
}
}
iOS 【手勢獲取cell位置】【點擊cell獲取indexpath】