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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With