iosobjective-canimationcore-animationfacebook-pop

How to animate UIView layer background color with Facebook Pop Animation Framework?


Facebook just open sourced their awesome POP animation framework which is built from Core Animation, and I can't figure out how to animate a layers background color.

Here's my code:

POPBasicAnimation *colorAnimation = [POPBasicAnimation animation];
colorAnimation.property = [POPAnimatableProperty propertyWithName:kPOPViewBackgroundColor];

if (_pressed)
{
    colorAnimation.toValue = (id)[UIColor redColor].CGColor;
}
else
{
    colorAnimation.toValue = (id)[UIColor greenColor].CGColor;
}

[_button pop_addAnimation:colorAnimation forKey:@"colorAnimation"];

The .toValue should only accept NSNumber or NSValue but I can't figure out how to pass in a color to animate as the .toValue.

Anyone out there know?


Solution

  • Ok so I solved it with this code hope it helps. I just changed POPBasicAnimation to POPSpringAnimation. Here's the code

    POPSpringAnimation *colorAnimation = [POPSpringAnimation animation];
    colorAnimation.property = [POPAnimatableProperty propertyWithName:kPOPViewBackgroundColor];
    
    if (clic)
    {
        colorAnimation.toValue = (id)[UIColor redColor].CGColor;
    }
    else
    {
        colorAnimation.toValue = (id)[UIColor greenColor].CGColor;
    }
    
    [imagen pop_addAnimation:colorAnimation forKey:@"colorAnimation"];