2

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.

Luca Bartoletti
  • 2,435
  • 1
  • 24
  • 46

4 Answers4

5

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

Srinivasan
  • 504
  • 6
  • 8
  • That's looks fantastic, nice bit of code. I played around with this and if (like me) you only want to change animation duration or ease in curves then you can skip the CATransaction code and just use the UIView sections at the beginning and end. – Brett Jun 21 '17 at 01:56
2

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

Colas
  • 3,473
  • 4
  • 29
  • 68
  • 1
    This should be `layer.speed` - discussed here: http://stackoverflow.com/a/18196592/404525 – Estel May 13 '15 at 10:12
1

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.

Dave Batton
  • 8,795
  • 1
  • 46
  • 50
0

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?

Carlos Guzman
  • 429
  • 6
  • 12