如何使用Facebook Pop Animation Framework动画UIView图层背景颜色?

Jus*_*ral 4 animation core-animation objective-c ios facebook-pop

Facebook刚开源他们的真棒POP动画框架,它是由Core Animation构建的,我无法弄清楚如何为图层背景颜色设置动画.

这是我的代码:

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"];
Run Code Online (Sandbox Code Playgroud)

.toValue应该只接受NSNumberNSValue但我无法弄清楚如何在色彩传递给动画作为.toValue.

有人知道吗?

小智 7

好的,所以我用这段代码解决了它希望它有所帮助.我刚刚将POPBasicAnimation更改为POPSpringAnimation.这是代码

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"];
Run Code Online (Sandbox Code Playgroud)