Luca Bartoletti
Luca Bartoletti

Reputation: 2447

UICollectionViewCell performBatchUpdates animation time

There is a way to customize timing on animations done via performBatchUpdates?

I have this code

[self.stepCollectionView performBatchUpdates:^{
    self.stepSelectedIndex = indexPath.row;

    UICollectionViewCell *cell = [self.stepCollectionView cellForItemAtIndexPath:indexPath];

    [UIView transitionWithView:cell
                      duration:0.5f
                       options: UIViewAnimationOptionLayoutSubviews | UIViewAnimationOptionBeginFromCurrentState
                    animations:^{
                        CGRect frame = cell.frame;
                        frame.size.height = 416;
                        cell.frame = frame;
                    }
                    completion:^(BOOL finished) {
                    }];
    } completion:^(BOOL finished) {        
}];

I would change the height of the UICollectionViewCell and at the same time reorganize the subviews of the UICollectionViewCell.

Upvotes: 2

Views: 7988

Answers (4)

Srinivasan
Srinivasan

Reputation: 524

There is a way you can customise the duration and the Timing function for UICollectionView's batch update. Try the below code. And here is how it looks https://youtu.be/R0VdC4dliPI

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];

[CATransaction begin];
[CATransaction setAnimationDuration:0.3];

[CATransaction setAnimationTimingFunction:[CAMediaTimingFunction functionWithControlPoints:0 :1.8 :0 :1]];

[self.menuCollectionView performBatchUpdates:^{
    [self.menuCollectionView insertItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:index inSection:0]]];
    [animatableMenuItems insertObject:@"" atIndex:index];
} completion:^(BOOL finished) {

}];

[CATransaction commit];
[UIView commitAnimations];

Find the full source code for the example at https://github.com/DoddaSrinivasan/MultiRowUITabBar

Upvotes: 5

Colas
Colas

Reputation: 3573

Yes you can change the duration of this animation. Change the layer.speed property of your UICollectionView.

Upvotes: 2

Dave Batton
Dave Batton

Reputation: 8835

Just wrap it up in a -[UIView animateWithDuration:animations:] block with your desired animation. It's probably not the correct way to do it, but it seems to work fine for me with iOS 8.

Upvotes: 1

Carlos Guzman
Carlos Guzman

Reputation: 429

No, there is no way to customize the timing of the animation caused by performBatchUpdates. It looks like you are trying to animate just on Cell in particular in your collectionview. Why not just use + (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations instead?

Upvotes: 0

Related Questions