iOS 【手勢獲取cell位置】【點擊cell獲取indexpath】

如何獲取手指點擊的cell位置:get

1,首先建立一個長按(能夠是點擊或者其餘手勢)it

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

2,在方法中進行實現table

- (void)handleLongPress:(UILongPressGestureRecognizer *)recognizerselect

{方法

//假如是開始點擊xpath

if (recognizer.state == UIGestureRecognizerStateBegan )tab

  {  //獲取當前點擊的indexpathview

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

          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的位置

  }

}

相關文章
相關標籤/搜索