简体   繁体   中英

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 .

I would like to get the screen location of a cell of my UICollectionView.

在此处输入图片说明

I've followed this tutorial to build the view:

You can find the point of your cell by using:

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

But if this will give you with respect to the collectionView . If you need to find the centre with respect to main view , you need to go through all the 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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