【问题标题】:"Red alert" animation effect with Quartz 2D or CALayer animation?Quartz 2D 或 CALayer 动画的“红色警报”动画效果?
【发布时间】:2011-12-08 20:50:40
【问题描述】:

我是动画新手,我只是找不到有关如何创建警报灯(闪烁的简单红色警报灯)的数据。

我知道如何制作 CALayer 动画和 Quartz 2D 的基础知识,我只是在寻找有关如何实现背光效果的教程或方向?

谢谢 沙尼

【问题讨论】:

  • 两个图像都分配给一个带有动画延迟设置的 UIImageView。 (UIImageView animationImages, UIImageView animationDuration, UIImageView animationRepeatCount)
  • 你的意思是用 alpha 动画在它们之间切换?
  • 不,UIImageView 具有动画功能 - 您可以为其分配多个图像并通过它们进行动画处理。

标签: ios animation calayer quartz-2d


【解决方案1】:

非常老套的代码(可以工作,但尽量不要在生产中使用):

self.uiView1.backgroundColor = [UIColor redColor];

CABasicAnimation* selectionAnimation1 = [CABasicAnimation 
                                        animationWithKeyPath:@"opacity"];

selectionAnimation1.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];

selectionAnimation1.fromValue = [NSNumber numberWithFloat:0.0];
selectionAnimation1.toValue = [NSNumber numberWithFloat:1.0];

selectionAnimation1.duration = 0.10;
selectionAnimation1.repeatCount = 20;

[self.uiView1.layer addAnimation:selectionAnimation1
                       forKey:@"opacity"];


self.uiView2.backgroundColor = [UIColor blackColor];

CABasicAnimation* selectionAnimation2 = [CABasicAnimation 
                                        animationWithKeyPath:@"opacity"];

selectionAnimation2.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];

selectionAnimation2.fromValue = [NSNumber numberWithFloat:1.0];
selectionAnimation2.toValue = [NSNumber numberWithFloat:0.0];

selectionAnimation2.duration = 0.10;
selectionAnimation2.repeatCount = 20;

[self.uiView2.layer addAnimation:selectionAnimation2
                          forKey:@"opacity"];

uiView1 & uiView2 完全重叠。您可以用两个 UIImageView 替换两个 uiView,其中一个具有打开的光(红色)图像和一个关闭光(黑色/灰色)的图像。在这种情况下,背景颜色的变化将是多余的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-10
    • 2011-11-05
    • 1970-01-01
    • 1970-01-01
    • 2011-08-03
    • 2014-04-15
    相关资源
    最近更新 更多