问题描述
我有一个带有142个单元格的 UICollectionView
。 7.5随时可见。
I have a UICollectionView
with 142 Cells. 7.5 are visible at any one time.
我将一个单元格从 indexPath
0移到100。 b $ b但是我也想滚动到那个新位置。
I'm moving a cell from indexPath
0 to say 100.But I also want to scroll to that new position.
下面的代码可以正常工作。但是,它会为移动和滚动设置动画效果,但随后将这些单元加载到中央/移动单元的前面和后面。
我认为是因为单元可重复使用。但是使用142,我无法全部预加载
The code below works fine. But it animates the move and scroll, but then loads the cells in front of and behind the central/moved cell afterwards.I think its because the cells are reusable. but with 142, I can't pre-load all of them
效果不是最好的,我想预加载新位置周围的单元格,4 indexPath
100之前和之后的4,然后查看移动和滚动的动画。您能帮忙吗?
Its not the nicest effect, I would like to pre-load the cells surrounding the new position, 4 before and 4 after indexPath
100, and then see the animation of the move and scroll. can you help please?
UIView.animateWithDuration(animationSpeed, animations: {() -> Void in
self.collectionView.layoutIfNeeded()
self.collectionView.scrollToItemAtIndexPath(NSIndexPath(forItem:self.indexPathSelected.row,
inSection:0),
atScrollPosition: .CenteredHorizontally,
animated: true)
})
推荐答案
我找到的唯一答案是在动画中添加几秒钟。这样,在滚动到达时加载单元格
The only answer I have found, is to add a few seconds to the animation. That way the cells are loaded when the scroll arrives
这篇关于UICollectionview scrollToItemAtIndexPath,在完成动画之前不加载可见单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!