ios - 获取 tableviewCell 在 tableview 的 superview 坐标系内的中心

标签 ios cgpoint superview

您可以使用以下方法获取单元格在其 super View 或 tableView 坐标内的中心点:

  CGPoint center = cell.center;

如果tableview的superview是UIView,如何在tableview的superview的坐标内获取单元格的中心点?

编辑:

单元格位于 tableView 中,tableView 位于 self.view 中。我主要关心 y 坐标。我做了一个测试来查看值应该是什么,但没有从 ConvertPointToView 获得所需的结果:

//debugger values appear below each line
CGRect viewRect = self.view.frame;
//(origin = (x = 0, y = 0), size = (width = 320, height = 568))
CGRect tableRect = self.tableView.frame;
//(origin = (x = 0, y = 108), size = (width = 320, height = 411))
 CGPoint prelimcenter = cell.center;
CGPoint center = prelimcenter;
//(x = 160, y = 242)
prelimcenter = [cell convertPoint:prelimcenter toView:self.view];
// (x = 160, y = 526) 

我预计 Y 坐标的差异约为 108,即帧之间的差异。然而,使用convertPoint 的点差异是284。我的语法/代码可能有什么问题?

最佳答案

您可以使用convertPoint:toView:方法。这是Apple's documentation的链接.

CGPoint center = cell.center;
center = [cell convertPoint:center toView:yoursuperview];

这应该将其转换为指定 View 的坐标系。

关于ios - 获取 tableviewCell 在 tableview 的 superview 坐标系内的中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54681132/

相关文章:

ios - ViewWillAppear 中的代码不起作用,为什么?

ios - 解析接收邮件FB SDK

swift - cgpoint 的颜色会更改所有行,并且只应更改新行

objective-c - 将 CGPoint 传递给另一个方法以 (inf, inf) 结尾

iphone - 隐藏 super View 而不隐藏其 subview

ios - UIView superview 属性是弱还是强?

ios - 将阴影添加到 UIImageView 的顶部和底部

ios - Xcode - 错误 ITMS-90635 - bundle 中的 Mach-O 无效 - 正在提交到应用商店

objective-c - 将 NSValue 转换回 CGPoint

objective-c - 在 super View 上获取鼠标按下事件