How to animate the background color of a UIView layer using Facebook Pop Animation Framework?

Facebook just opened up its awesome POP animation structure , which is built from Core Animation , and I can't figure out how to animate the background color of the layers.

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

.toValueshould only accept NSNumberor NSValue, but I can’t understand how to convey color for animation like .toValue.

Somebody knows?

+4
source share
2 answers

Ok, so I decided this with the help of this code to hope this helps. I just changed POPBasicAnimation to POPSpringAnimation. Here is 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"];
+7

POP.

POPBasicAnimation

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

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

POPSpringAnimation

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

[_yourView pop_addAnimation:springAnimation forKey:@"backgroundColorChange"];
+2

Source: https://habr.com/ru/post/1538647/


All Articles