I am moving a cell from indexPath 0 To 100.
But I also want to scroll to that new position.
The code below works fine. But it animates moving and scrolling, but then loads the cells to the center/moving cells before and after.< br>I think it’s because the cells are reusable. But 142, I can’t preload all of them
It’s not the best effect, I want to preload the cells around the new location, in the indexPath 100 before and after 4, then check the animation of moving and scrolling. Can you help?
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 OR up
add “view.layoutIfNeeded() “Before implementing scrollToItem method, Ideally in viewWillAppear
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
view.layoutIfNeeded()< br /> colView.scrollToItem(at: IndexPath(item: 4, section: 0), at: .centeredHorizontally, animated: true))
I have a UICollectionView with 142 cells. Can be seen at any time 7. 5.
I am moving a cell from indexPath 0 to 100.
But I also want to scroll to that new position.
The code below works fine. But it animates moving and scrolling, but then loads the cells to the center/moving cells before and after.
I think this is because the cells are reusable. But 142, I can’t preload all of them
It is not the best effect, I want to preload the cells around the new position, before and after indexPath 100 and 4, and then view the animation of moving and scrolling. Can you help?
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 OR up
add “view.layoutIfNeeded()” before implementing scrollToItem method, Ideally in viewWillAppear
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
view.layoutIfNeeded()
colView.scrollToItem(at: IndexPath(item : 4, section: 0), at: .centeredHorizontally, animated: true)}