如何在UITableview中获得第一个单元格(x,y)的确切起始位置?

Dip*_*jak 2 iphone ios

如何在UITableview中获得第一个单元格的准确起始位置?

Har*_*son 9

首先,您需要在表格中获取矩形

CGRect cellRectInTable = [tableView rectForRowAtIndexPath:indexPath];
Run Code Online (Sandbox Code Playgroud)

然后你转换为超级视图

CGRect cellInSuperview = [tableView convertRect:cellRectInTable toView:[tableView superview]];
Run Code Online (Sandbox Code Playgroud)

你也可以好运

CGRect cellInWindow = [tableView convertRect:cellRectInTable toView:nil];
Run Code Online (Sandbox Code Playgroud)

然后你可以访问这些rects的起源

...rect.origin.x
...rect.origin.y
Run Code Online (Sandbox Code Playgroud)

Apple Docs UIView convRect

Apple Docs rectForRowAtIndexPath