Question

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?

Was it helpful?

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"];

OTHER TIPS

You can animate background color change on every view with POP.

Example with POPBasicAnimation

POPBasicAnimation *basicAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPViewBackgroundColor];
basicAnimation.toValue = [UIColor greenColor];

[_yourView pop_addAnimation:basicAnimation forKey:@"backgroundColorChange"];

Example with POPSpringAnimation

POPSpringAnimation *springAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewBackgroundColor];
springAnimation.toValue = [UIColor greenColor];

[_yourView pop_addAnimation:springAnimation forKey:@"backgroundColorChange"];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top