从 UITableviewCell 获取 CollectionView 单元格的屏幕位置

Getting the screen location of a CollectionView cell from a UITableviewCell

我有一个 ViewController 和一个 UITableView 在这个 tableView 的每个单元格中,我都有一个 UICollectionView.

我想获得我的 UICollectionView 的一个单元格的屏幕位置。

我已按照 this 教程构建视图:

您可以使用以下方法找到 cellpoint

let realCenter = collectionView.convert(cell.frame, to: collectionView.superview)

不过要是这样的话就给你敬上了collectionView。如果你需要找到关于 main view 的中心,你需要遍历所有 superview.

let realCenter = collectionView.convert(cell.frame, to: collectionView.superview?.superview?.superview?.superview)

loop通过浏览量找到你的superview然后找到你要找的frame