Getting the exact location of a UITableViewCell

后端 未结 9 663
滥情空心
滥情空心 2021-01-30 20:10

Given a UITableView, how can I find the location of a specific UITableViewCell? In other words, I want to get its frame relative to my iPhone screen, n

9条回答
  •  情深已故
    2021-01-30 20:58

    Jhaliya's answer wasn't quite enough for me, I needed to do some more manipulations to get it working. My tableView was added to a viewController and its location on the right half way down the screen. So you need to take the tableView origin into account aswel as the scroll offset.

    CGRect rowRect = [tableView rectForRowAtIndexPath:indexPath];
    CGPoint offsetPoint = [self.infoTableView contentOffset];
    
    // remove the offset from the rowRect
    rowRect.origin.y -= offsetPoint.y;
    
    // Move to the actual position of the tableView
    rowRect.origin.x += self.infoTableView.frame.origin.x;
    rowRect.origin.y += self.infoTableView.frame.origin.y;
    

提交回复
热议问题