Aashish Nagar
Aashish Nagar

Reputation: 1227

CollectionView should adjust scroll postion with animation

I am using a collection to delete a item I am just deleting an item from datasource and then reloading the CollectionView. on deleting the cell collection adjust its scroll position. This is happening without animation. I want the CollectionView to adjust scroll position with animation. How to do that ?

Upvotes: 2

Views: 421

Answers (3)

Maulik Pandya
Maulik Pandya

Reputation: 2220

Following code snippet may help you

Get your current indexPath and delete row from below code may solve your problem

yourCollectionView.deleteItems(at: [indexPath!])

Note : No need to reload your CollectionView

Upvotes: 1

Kisoth Srinathan
Kisoth Srinathan

Reputation: 115

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

self.collectionView.scrollToItem(at: IndexPath, atScrollPosition: .centeredHorizontally, animated: true)
}

Upvotes: 1

Sagar Bhut
Sagar Bhut

Reputation: 657

you try that code

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
self.images.removeObject(at: indexPath.item)
                self.collectionView.reloadData()
}

Upvotes: 0

Related Questions