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?
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"];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With