【问题标题】:How to animate UIView layer background color with Facebook Pop Animation Framework?如何使用 Facebook Pop Animation Framework 为 UIView 图层背景颜色设置动画?
【发布时间】:2014-04-29 22:30:25
【问题描述】:

Facebook 刚刚开源了他们很棒的 POP 动画 框架,该框架是由 Core Animation 构建的,我不知道如何为图层背景颜色设置动画。 p>

这是我的代码:

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。

有人知道吗?

【问题讨论】:

  • 该代码对我来说似乎可以正常工作。什么不工作?

标签: ios objective-c animation core-animation facebook-pop


【解决方案1】:

好的,我用这段代码解决了这个问题,希望对您有所帮助。我刚刚将 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"];

【讨论】:

  • 现在要试试这个。感谢您的回复。
  • 效果很好。不知道为什么基本动画不接受它,因为当我使用普通 CABasicAnimation 时它工作正常。一定是他们的错误。
【解决方案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"];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-12-23
    • 1970-01-01
    • 2019-07-10
    • 2016-01-02
    • 1970-01-01
    • 2022-12-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多