iosuicollectionviewuicollectionviewlayout

Resize the cell of UICollectionView without the reload methods


How can I resize the cell size of UICollectionView without reload methods? Just want to call following method on some event. I do not want to reload UICollectionView or any of its section or row.

   func collectionView(collectionView: UICollectionView,
                    layout collectionViewLayout: UICollectionViewLayout,
                           sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize 

Solution

  • I got the solution to my question with following line of code.

    collectionView?.collectionViewLayout.invalidateLayout()
    

    N.B. To animate this resizing, use UIView.animate :

    let duration: TimeInterval = 0.3
    UIView.animate(withDuration: duration, animations: {
        collectionView.collectionViewLayout.invalidateLayout() 
    })