Mason Cloud
Mason Cloud

Reputation: 1306

I need help animating UICollectionView cell size when collection view size changes

I have a UICollectionView that takes up the entire screen, and inside it are cells that are the same exact size as the collection view. When the user hits a button, the collection view animates to take up only half the screen (and another view is shown beside it). This is fine, but the cells themselves are still the size of the original collection view.

I can call invalidateLayout on the collection view's layout, and this will cause collectionView:layout:sizeForItemAtIndexPath: to be called and the cells are all recalcualted, and the sizes are changes, but these do not animate, they simply snap to the new size.

Is there a way to animate these cell size changes at the same time, or in the same animation block that animates the size change to the parent collection view?

Upvotes: 0

Views: 315

Answers (1)

Sunny Shah
Sunny Shah

Reputation: 13020

 [_collectionView performBatchUpdates:^{

    for (int i =0; i<count; i++) {
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
        UICollectionViewCell *cell = [_collectionView cellForItemAtIndexPath:indexPath];
        cell.layer.transform = CATransform3DMakeScale(0.9, 0.9, 1);
    }

} completion:nil];

Upvotes: 1

Related Questions