Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

itemSize not animating with setCollectionViewLayout(toLayout, animated: true);

Hello I'm trying to work with UICollection views and have them have multiple layouts.

When I use swift/obj-cs setCollectionViewLayout(toLayout, animated: true); the animation does rearrange the cells but the item in the cells jump to the final size instead of growing gradually along with the cell and the end result is a bad looking animations.

Here are my two layouts I'm switching 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 the 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 the layouts:

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

}

Is there anyway to get the itemSize animating properly? or to create my own custom animation for the transition? I tried to do the batchupdates method but that gives me the same result where the itemsize jumps to its final value.

like image 323
primaryartemis Avatar asked Nov 28 '25 18:11

primaryartemis


1 Answers

I find that UIColletionViewCell and UIColletionViewCell.contentView have different behavior during animation invoked by setCollectionViewLayout(toLayout, animated: true), the cell's size grows gradually while the contentView jumps to the final size. But apple suggests the content view is the main view to which you should add you cell's custom content.

like image 97
jun luan Avatar answered Dec 01 '25 09:12

jun luan