简体   繁体   English

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

[英]Getting the screen location of a CollectionView cell from a UITableviewCell

I have a ViewController with a UITableView And in each cells of this tableView, I have a UICollectionView . 我有一个带有UITableViewViewController ,并且在此tableView的每个单元格中,都有一个UICollectionView

I would like to get the screen location of a cell of my UICollectionView. 我想获取UICollectionView单元格的屏幕位置。

在此处输入图片说明

I've followed this tutorial to build the view: 我已经按照教程构建了视图:

You can find the point of your cell by using: 您可以使用以下方法找到cellpoint

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

But if this will give you with respect to the collectionView . 但这是否会使您对collectionView有所尊重。 If you need to find the centre with respect to main view , you need to go through all the superview . 如果需要找到相对于main view的中心,则需要遍历所有superview

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

loop through the views to find your superview you are looking for and then find the frame loop视图以找到要查找的superview ,然后找到frame

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM