Search code examples
ios7core-animation

iOS 7 - CoreAnimation not working for UICollectionViewCell


I have a simple animation of shaking of cell icons in UICollectionView, similar to spring board edit mode. Animation was working well in iOS 6, but not working in iOS 7.

Here is the sample code.

- (void)startQuivering
{
    CABasicAnimation *quiverAnim = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    float startAngle = (-1) * M_PI/180.0;
    float stopAngle = -startAngle;
    quiverAnim.fromValue = [NSNumber numberWithFloat:startAngle];
    quiverAnim.toValue = [NSNumber numberWithFloat:3 * stopAngle];
    quiverAnim.autoreverses = YES;
    quiverAnim.duration = 0.12;
    quiverAnim.repeatCount = HUGE_VALF;
    float timeOffset = (float)(arc4random() % 100)/100 - 0.50;
    quiverAnim.timeOffset = timeOffset;
    CALayer *layer = self.layer;
    [layer addAnimation:quiverAnim forKey:@"quivering"];
}

Similarly Stoping the quivering animation.

- (void)stopQuivering
{
    CALayer *layer = self.layer;
    [layer removeAnimationForKey:@"quivering"];
}

Calling these methods in applyLayoutAttributes: method in my custom UICollectionViewCell class, depending on long press gesture and related flag

I am unable to figure out the issue, so I need help from the developers.


Solution

  • Finally Solved the issue. Its similar to this question How to refresh UICollectionViewCell in iOS 7? -applyLayoutAttributes: was not getting called properly, could solve the issue by overriding isEqual: method in custom UICollectionViewLayoutAttributes subclass and calling super -applyLayoutAttributes:.