Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 1000
Justin Cabral Avatar asked Jan 11 '23 16:01

Justin Cabral


1 Answers

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"];
like image 192
Abel7x Avatar answered Jan 18 '23 13:01

Abel7x