ItemSize is not animated with setCollectionViewLayout (toLayout, animated: true);

Hello I am trying to work with UICollection views and have multiple layouts.

When I use swift / obj-cs setCollectionViewLayout (toLayout, animated: true); the animation reorders the cells, but the element in the cells jumps to its final size rather than gradually growing with the cell, and the end result is bad looking animations.

Here are my two layouts that I switch between:

{
    override init()
    {
        super.init()
        minimumLineSpacing = 20.0;
        minimumInteritemSpacing = 0.0;
        itemSize = CGSizeMake(80.0, 80.0)
        sectionInset = UIEdgeInsetsMake(20.0, 60.0, 20.0, 60.0)
    }


    required init(coder: NSCoder) {
        fatalError("NSCoding not supported")
    }

      

And other:

{
    override init()
    {
        super.init()
        minimumLineSpacing = 10.0;
        minimumInteritemSpacing = 10.0;
        itemSize = CGSizeMake(150.0, 150.0)
        sectionInset = UIEdgeInsetsMake(20.0, 20.0, 20.0, 20.0)
    }


    required init(coder: NSCoder) {
        fatalError("NSCoding not supported")
    }

      

And the code used to change layouts:

func changeLayoutWithLayout(toLayout:UICollectionViewFlowLayout)
{
    self.setCollectionViewLayout(toLayout, animated: true);

}

      

Is there a way to get the itemSize animation correct? or create my own custom animation for the transition? I tried to execute batchupdates method, but it gives me the same result when itemsize goes to its final value.

+3


source to share


1 answer


I found that UIColletionViewCell

both UIColletionViewCell.contentView

have different behavior during the animation triggered setCollectionViewLayout(toLayout, animated: true)

, the cell size gradually increases and contentView

goes to the final size. But apple suggests that the content view is the main view you should add custom cell content to.



0


source







All Articles