自定义 CollectionView,如何在 ScrollingEnded 上获取当前项目

Custom CollectionView, how to get current items on ScrollingEnded

我正在创建自定义布局 collectionView,类似于文档 here。我在 collectionView 之外有一些文本视图,我想根据屏幕中间的当前项目进行填充,我知道我可以使用 CollectionView.IndexPathsForVisibleItems 获取当前可见的项目。我的问题是如何才能到达 scrollingEnded 事件或类似事件,以便我可以在那里调用 CollectionView.IndexPathsForVisibleItems 并获取填充文本字段所需的数据?

我尝试在 MyCustomCollectionViewSource 中覆盖 ScrollAnimationEnded,但由于某种原因它从未触发。我还考虑过可能使用 SupplementaryView,但我无法找到它与自定义布局一起使用的任何示例代码。

My question is how can i get to the scrollingEnded event or something similar so that i can call CollectionView.IndexPathsForVisibleItems in there and get the data i need to populate the text fields?

有一个Scrolled方法可以实现(根据ContentOffset检查是否需要加载更多),这个方法需要在UICollectionViewDelegate里面。

public class MyCollectionDelegate : UICollectionViewDelegate {
    #region Computed Properties
    public CollectionView mCollectionView { get; set;}
    #endregion

    #region Constructors
    public MyCollectionDelegate (CollectionView collectionView)
    {
        // Initialize
        mCollectionView = collectionView;
    }
    #endregion

    public override void Scrolled(UIScrollView scrollView)
    {
        //base.Scrolled(scrollView);
        if (scrollView.ContentOffset.Y + scrollView.Frame.Size.Height - scrollView.ContentSize.Height > 30)
        {
            // load more data 
        }
}

然后为 CollectionView 设置 Delegate 如下:

 this.collectionView.Delegate =  new MyCollectionDelegate(this.collectionView);

我使用 DecelerationEnded 解决了我的问题。