SWIFT – UICOLLECTIONVIEW SCROLLTOITEMATINDEXPATH, not loaded before the animation is completed before the visible cell

I have a UICollectionView with 142 cells. I can see 7.5 at any time.

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)}

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4104 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.