“红色警戒” Quartz 2D 或 CALayer 动画的动画效果?

发布于 2024-12-20 07:30:33 字数 127 浏览 5 评论 0原文

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

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

谢谢 沙尼

I am new to animations and I just can not find data on how to create an alert light (simple red alert light that flickers).

I know how to animate CALayer and the basics of Quartz 2D, I am just looking for a tutorial or direction on how to achieve back light effect?

Thanks
Shani

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痴意少年 2024-12-27 07:30:33

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

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 彼此完全重叠。您可以将两个 uiView 替换为两个 UIImageView,其中一个具有打开的灯图像(红色),另一个具有关闭的灯图像(黑色/灰色)。在这种情况下,背景颜色的变化将是多余的。

Very hacky code (works but try not using it in production):

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 completely overlap each other. You can replace the two uiView's with two UIImageView's, with one having an image of light turned on (red) and one with light turned off (black/gray). In which case background color change will be redundant.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文