Nikolay Nankov
Nikolay Nankov

Reputation: 273

How to animate single UICollectionView cell with duration

I am trying to animate the first cell's height and the rest to scroll up or down. Inside the cell is an image view with .ScaleAspectFill

I manage to do it if the transition is interactive with invalidateLayout() and sizeForItemAtIndexPath, but I can't figure out how to animate to an end state

Here's what I'm doing:

let cell = collectionView!.cellForItemAtIndexPath(NSIndexPath(forItem: 0,    inSection: 0)) as! HomeFeedCell
var size:CGSize = getNewSize(cell)

UIView.transitionWithView(collectionView!, duration: duration, options: .CurveEaseOut | .LayoutSubviews, animations: {
                cell.frame.size.height = size.height
            }, completion: nil)

This animates the first cell but doesn't move the rest of the cells. I tried invalidateLayout() or reloading the visible cells inside the animation block but it gives strange result

Upvotes: 0

Views: 1345

Answers (1)

Nikolay Nankov
Nikolay Nankov

Reputation: 273

So if anyone is stuck with the same the answer is to also call the collection view's performBatchUpdates with nil updates: block

let cell = collectionView!.cellForItemAtIndexPath(NSIndexPath(forItem: 0,    inSection: 0)) as! HomeFeedCell
var size:CGSize = getNewSize(cell)

UIView.transitionWithView(collectionView!, duration: duration, options: .CurveEaseOut | .LayoutSubviews, animations: {
                cell.frame.size.height = size.height
            }, completion: nil)

collectionView!.performBatchUpdates(nil, completion: nil)

Upvotes: 1

Related Questions