Search code examples
iosswiftcollectionview

ScrollToTtem is not smooth


I am using a colletionview images to scroll images horizontally. I am getting the index using didselectitem from the first collection view and through segue transition, I am using the selected index to pick the images from the array in the secondcollectionview.

Since I am using , ScrollToItem, when I am clicking, image[5], it takes me to the 6th image after skipping the first 5 images. Everything works, but the problem is, the transition is not smooth. I could see the first 5 images sliding for a fraction of second and its not cool. How to get a seamless transition while scrolling?


Solution

  • This worked for me with smooth transition (Horizontally) in a CollectionView. Please check your scrollToItem method.

    DispatchQueue.main.async {
            let nextItem: IndexPath = IndexPath(item: 4, section: 0)
            self.collectionCatlogue.scrollToItem(at: nextItem, at: .centeredHorizontally, animated: true)
        }
    

    If this things not works for you then please share your code.