我有一个UICollectionView
有 142 个电池。 7.5 随时可见。
我正在从以下位置移动一个单元格indexPath
0 表示 100。
但我也想滚动到那个新位置。
下面的代码工作正常。但它对移动和滚动进行动画处理,然后加载中央/移动单元前面和后面的单元。
我认为这是因为细胞是可重复使用的。但对于 142,我无法预加载所有内容
这不是最好的效果,我想预加载新位置周围的单元格,前 4 个,后 4 个indexPath
100,然后看到移动和滚动的动画。你能帮忙吗?
UIView.animateWithDuration(animationSpeed, animations: {() -> Void in
self.collectionView.layoutIfNeeded()
self.collectionView.scrollToItemAtIndexPath(NSIndexPath(forItem:self.indexPathSelected.row,
inSection:0),
atScrollPosition: .CenteredHorizontally,
animated: true)
})
Swift 3.0 或更高版本
在实现scrollToItem方法之前添加“view.layoutIfNeeded()”,最好在viewWillAppear中
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
view.layoutIfNeeded()
colView.scrollToItem(at: IndexPath(item: 4, section: 0), at: .centeredHorizontally, animated: true)}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)