简体   繁体   中英

how to animate itemSize from UICollectionViewFlowLayout?

I'm using a UICollectionView to display a set of graphics on several rows and columns. User can use pinchGesture to zoom in / zoom out.

When user zoom in the graph size increases and user zoom out the graph size decreases. To change the size of graph I'm just changing the property itemSize from UICollectionViewFlowLayout . It works great but I'm unable to animate the change with the following code:

    [UIView transitionWithView:self.theCollectionView
                  duration:0.5f
                   options:UIViewAnimationOptionCurveLinear
                animations:^() {
                    _theFlowLayout.itemSize = cellSize;
                }
                completion:nil];

Any idea how to animate this change?

Regards,

Sébastien.

You can use the collection view's performBatchUpdates method which will invalidate and re-query your layout, animating to any new values.

Something like this:

_theFlowLayout.itemSize = cellSize;
[self.theCollectionView performBatchUpdates:nil completion:nil];

You don't get to control the timing or curve of the animation, unfortunately.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM