UICollectionViewCell - contents do not animate alongside cell's contentView

前端 未结 3 575
予麋鹿
予麋鹿 2021-01-31 20:32

Problem looks like this: http://i.imgur.com/5iaAiGQ.mp4 (red is a color of cell.contentView)

Here is the code: https://github.com/nezhyborets/UICollectionViewContentsAni

3条回答
  •  心在旅途
    2021-01-31 21:06

    The solution is very easy. First, in ViewController.collectionView(_,didSelectItemAt:), write only this:

    collectionView.performBatchUpdates({
            self.selectedIndex = indexPath.row
        }, completion: nil)
    

    And then, in the class ProblematicCollectionViewCell add this func:

    override func apply(_ layoutAttributes: UICollectionViewLayoutAttributes) {
        super.apply(layoutAttributes)
    
        self.layoutIfNeeded()
    }
    

    Enjoy!

提交回复
热议问题