如何获取CollectionView中cell的相对位置

How to get the relative position of a cell in CollectionView

我想知道如何获取集合视图中单元格相对于应用 window 的相对位置?我看到了 swift 和表格的一些示例,但找不到 Xamarin.iOS

翻译本thread中的解决方案:

public class collectionViewDelegate : UICollectionViewDelegate {

    UIView view;

    public collectionViewDelegate(UIView v)
    {
        //get the parent v when create collectionViewDelegate instance
        this.view = v;
    }

    public override void ItemSelected(UICollectionView collectionView, NSIndexPath indexPath)
    {

        UICollectionViewCell cell = (UICollectionViewCell)collectionView.DequeueReusableCell("CollectionViewCell",indexPath);

        CGRect frame = new CGRect(0,0,cell.Frame.Size.Width,cell.Frame.Size.Height);

        frame.Location = collectionView.ConvertPointToView(cell.Frame.Location, this.view);
    }
}