如何使用Facebook Pop动画框架为UIView图层的背景颜色添加动画效果?

4
Facebook刚开源了他们的出色的POP动画框架,它是基于核心动画构建的。我不知道如何为图层动画背景颜色。以下是我的代码:
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"];
.toValue 应该只接受 NSNumber 或者 NSValue 类型,但是我不知道如何传递一个颜色作为 .toValue 进行动画。

有人知道吗?


那段代码在我这里似乎正常工作。有什么问题吗? - Enrico Susatyo
2个回答

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

现在我要尝试一下。感谢您的回复。 - Justin Cabral
运行得很好。不知道为什么基本动画不接受它,因为当我使用普通的CABasicAnimation时,它可以正常工作。一定是他们那边出了错误。 - Justin Cabral

2
您可以使用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"];

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接