Xamarin.ios 如何在CollectionView中获取单元格的相对位置

Xamarin.ios 如何在CollectionView中获取单元格的相对位置,xamarin.ios,uicollectionview,Xamarin.ios,Uicollectionview,我想知道如何获得集合视图中单元格相对于应用程序窗口的相对位置?我看到了一些swift和forms的示例,但我找不到任何Xamarin的示例。iOS将解决方案翻译为: 请给我们看一些相关代码。如果您在swift中找到解决方案,您也可以在此处共享,我们可以帮助您将其转换为C#解决方案。代码如下:我用C#中的解决方案添加了一个答案。 public class collectionViewDelegate : UICollectionViewDelegate { UIView view;

我想知道如何获得集合视图中单元格相对于应用程序窗口的相对位置?我看到了一些swift和forms的示例,但我找不到任何Xamarin的示例。iOS将解决方案翻译为:


请给我们看一些相关代码。如果您在swift中找到解决方案,您也可以在此处共享,我们可以帮助您将其转换为C#解决方案。代码如下:我用C#中的解决方案添加了一个答案。
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);
    }
}