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

时间:2020-07-23 12:47:58

标签: xamarin.ios uicollectionview

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

1 个答案:

答案 0 :(得分:1)

翻译此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);
    }
}
相关问题