【问题标题】:How to get the relative position of a cell in CollectionView如何在 CollectionView 中获取单元格的相对位置
【发布时间】:2020-07-23 12:47:58
【问题描述】:

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

【问题讨论】:

  • 请给我们一些相关的代码。如果您在 swift 中找到解决方案,也可以在这里分享,我们可以帮助您将其转换为 C# 解决方案。
  • 我在 C# 中添加了一个带有解决方案的答案。

标签: xamarin.ios uicollectionview


【解决方案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);
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-14
    • 1970-01-01
    • 1970-01-01
    • 2011-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多