UICollectionview scrollToItemAtIndexPath, not loading visible cells until animation complete

collectionview scrolltoitem not working
uicollectionview scroll to item
uicollectionview scroll to next cell

I have a UICollectionView with 142 Cells. 7.5 are visible at any one time.

I'm moving a cell from indexPath 0 to say 100. But I also want to scroll to that new position.

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

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)

})

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

UIcollectionView scrollToitemAtIndexPath does not work for non , Swift 3.0 OR up. add "view.layoutIfNeeded()" before implementing scrollToItem method, Ideally in viewWillAppear. override func viewWillAppear(_ animated:  I have a UICollectionView with 142 Cells. 7.5 are visible at any one time. I'm moving a cell from indexPath 0 to say 100. But I also want to scroll to that new position. 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 use dispatch_async to update the UI and it works.

let numberOfSections = self.collectionView.numberOfSections()
let numberOfRows = self.collectionView.numberOfItemsInSection(numberOfSections-1)

    if numberOfRows > 0 {
        dispatch_async(dispatch_get_main_queue(), {
            let indexPath = NSIndexPath(forRow: numberOfRows-1, inSection: (numberOfSections-1))
            self.collectionView.scrollToItemAtIndexPath(indexPath, atScrollPosition: .Bottom, animated: true)
        })
    }

swift, You should call the method scrollToItemAtIndexPath in the viewDidAppear, collectionView to abruptly scroll/animate to the the index I wanted it scroll to. layoutIfNeeded() // call this before you call scrollToItem let lastItemIndex UICollectionview scrollToItemAtIndexPath, not loading visible cells until animation complete  I have a UIView where I added a UICollectionView. Now this view is shown on app start up. At the same time I'm scrolling to a certain position in my collection view. Therefore I use scrollToItemAtIndexPath. The problem now is that it scrolls to a wrong position, because the collection view has the wrong size at the beginning: If you start the


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

scrollToItemAtIndexPath:atScrollPosition:animated:, swift - UICollectionview scrollToItemAtIndexPath, not loading visible cells until animation complete -. Get link; Facebook; Twitter; Pinterest  Have managed to create a UICollectionView with custom LayoutAttributes and reusable custom cell which calculate the height of it for an image. The problem that I have is that I want to programmatically scroll to the Nth index but scrollToItemAtIndexPath seems to work only for the visible ones.


The best solution I found was to use DispatchQueue.

Swift 4.2:

 override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    if let index = items.firstIndex(of: preSelectedItem) {
        DispatchQueue.main.async {
            self.collectionView.scrollToItem(at: IndexPath(item: index, section: 0), at: .top, animated: false)
        }
    }
}

Animating UICollectionView contentOffset does not display non , scrollToItemAtIndexPath:atScrollPosition:animated: Scrolls the collection view contents until the specified item is visible. SDKs. iOS 6.0+; Mac Catalyst 13.0+  It seems that UIKit would crash when -scrollToItemAtIndexPath:atScrollPosition:Animated is called when the UICollectionView is not yet laid out, as you could see on Radar. So you can only put it in viewDidAppear and and viewDidLayoutSubviews on iOS7 and only put it in viewDidAppear on iOS6. why even viewDidLayoutSubviews is excluded on iOS6 is shown in your log:


User Hiren Panchal, UICollectionview scrollToItemAtIndexPath, not loading visible cells until animation complete. I have a UICollectionView with 142 Cells. 7.5 are visible at any one  Update April 13, 2015 Updated for Xcode 6.3 / Swift 1.2. Update note: This tutorial was updated for Swift and iOS 8 by Richard Turton.Original post by Brandon Trebitowski.. In the first part of this tutorial, you saw how to use a UICollectionView to display a grid of photos.


UICollectionView ScrollToItemAtIndexPath does not work for non , Animating UICollectionView contentOffset does not display non-visible cells - ios. However, only the cells that are visible at the end of the animation are actually to improve performance by waiting until the end of the scroll before updating. Use :scrollToItemAtIndexPath instead: [UIView animateWithDuration:duration  An option that specifies where the item should be positioned when scrolling finishes. For a list of possible values, see UICollection View.Scroll Position.


ios - UICollectionView initial scroll lag? - Stack Overflow, UICollectionview scrollToItemAtIndexPath, not loading visible cells until animation complete · stackoverflow.com · 15 · Get tapped word from UITextView in Swift. Questions: I would like to scroll the UICollectionView to the bottom so the last item is in the view. I have tried to use scrollToItemAtIndexPath but it does not seem to be working. I want this to happen after I have completed a query with Parse.com Thanks var query = PFQuery(className:"Chat") // query.whereKey("user", equalTo:currentUser