如何知道在调用scrollToItemAtIndexPath:之后是否实际滚动UICollectionView?

时间:2016-07-07 09:54:25

标签: ios uicollectionview uiscrollviewdelegate

我使用scrollToItemAtIndexPath:atScrollPosition:animated滚动UICollectionView。我必须在发生自动滚动时禁用某些功能,然后在滚动结束时重新启用它。当我尝试滚动到某个已经可见且不需要滚动的单元格时(例如,它是最后一个单元格和集合视图已经滚动到最后),会出现问题。在这种情况下,scrollViewDidEndDraggingscrollViewDidEndDecelerating都会被调用。

有没有办法知道scrollToItemAtIndexPath是否会实际滚动UICollectionView

2 个答案:

答案 0 :(得分:0)

我认为你可以保存最新的滚动视图偏移量&每次scrollView滚动时都跟踪它的变化。仅在重大更改后应用操作。

function saveFunction(){
    console.log("hej");
}

答案 1 :(得分:0)

您可以在调用scrollToItemAtIndexPath之前确定scrollToItemAtIndexPath是否会根据单元格的帧进行滚动。例如,如果您只希望单元格可见(UICollectionViewScrollPositionNone):

UICollectionViewLayoutAttributes* attrs = [collectionView layoutAttributesForItemAtIndexPath:indexPath];
CGRect frame = [collectionView convertRect:attrs.frame toView:self.view];
BOOL willScroll = !CGRectContainsRect(collectionView.frame, frame);

不幸的是,scrollToItemAtIndexPath并不能简单地告诉您它是否会滚动。