So I have a subclassed uicollectionflowlayout. I am trying to animate a cell size on selection as well as deselection. On did select cell I have this:
[CATransaction begin];
[CATransaction setCompletionBlock:^{
BubblesCollectionViewFlowLayout *layout = (BubblesCollectionViewFlowLayout *)bubblesView.collectionViewLayout;
[bubble.layer setCornerRadius:BIGGER_CELL_WIDTH_HEIGHT/2];
[layout setSize:CGSizeMake(BIGGER_CELL_WIDTH_HEIGHT, BIGGER_CELL_WIDTH_HEIGHT) forItemAtIndexPath:indexPathOfSelectedCell];
[bubble.cellLabel setFrame:CGRectMake(0.0f, BIGGER_CELL_WIDTH_HEIGHT/2-30.0f, BIGGER_CELL_WIDTH_HEIGHT, 60.0f)];
}];
/************* Cell Scale Animation *****************/
CABasicAnimation *animationScale = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
animationScale.fromValue = [NSNumber numberWithFloat:1.0];
animationScale.toValue = [NSNumber numberWithFloat:BIGGER_CELL_WIDTH_HEIGHT/CELL_WIDTH_HEIGHT];
[animationScale setDuration:0.3f];
[animationScale setValue:[NSNumber numberWithInt:animationTypeCellScale]
forKey:ANIMATION_TYPE_STRING];
[bubble.layer addAnimation:animationScale forKey:@"animationCellScale"];
/*BubblesCollectionViewFlowLayout *layout = (BubblesCollectionViewFlowLayout *)bubblesView.collectionViewLayout;
[bubble.layer setCornerRadius:BIGGER_CELL_WIDTH_HEIGHT/2];
[layout setSize:CGSizeMake(BIGGER_CELL_WIDTH_HEIGHT, BIGGER_CELL_WIDTH_HEIGHT) forItemAtIndexPath:indexPathOfSelectedCell];*/
/************** Cell label Animations ****************/
CAAnimationGroup *groupAnimation = [CAAnimationGroup animation];
[groupAnimation setDuration:0.3f];
CABasicAnimation *animationCellScale = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
animationCellScale.fromValue = [NSNumber numberWithFloat:1.0f];
animationCellScale.toValue = [NSNumber numberWithFloat:1.1f];
[animationCellScale setValue:[NSNumber numberWithInt:animationTypeLabelScale]
forKey:ANIMATION_TYPE_STRING];
[groupAnimation setAnimations:@[animationCellScale]];
[bubble.cellLabel.layer addAnimation:groupAnimation forKey:@"animationLabel"];
//[bubble.cellLabel setAlpha:0.0f];
/*[bubble.cellLabel setFrame:CGRectMake(0.0f, BIGGER_CELL_WIDTH_HEIGHT/2-30.0f, BIGGER_CELL_WIDTH_HEIGHT, 60.0f)];*/
[CATransaction commit];
The problem with this is that during the animation, the cells still assume the old layout attributes so the cells are still normal size. The animation happens nicely but when it finishes it quickly snaps back to the normal size before going into the CATransaction completion block. Thus, I see a sudden change from normal to bigger size after the animation. This is replicated but in the reverse order for deselection. Any helpful tips would be greatly appreciated