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
。
有人知道吗?
答案 0 :(得分: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"];
答案 1 :(得分: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"];