简体   繁体   English

动画时如何改变UIBezierPath笔画的颜色?

[英]How to Change Color of UIBezierPath Stroke Whilst Animating?

I was wondering if it was possible to change the color of a UIBezierPath strokeColor while its animating. 我想知道是否有可能在动画时更改UIBezierPath strokeColor的颜色。 For instance, if it goes past a certain angle like 45 deg, it changes from green to orange, and if it goes past 66 deg it goes from orange to red. 例如,如果它超过45度的某个角度,它会从绿色变为橙色,如果超过66度则会从橙色变​​为红色。

Somebody else suggested using a "gradual" (gradient) layer. 其他人建议使用“渐进”(渐变)层。 If you can create a gradient that meets your needs then that would work. 如果您可以创建满足您需求的渐变,那么这将起作用。

You could do just about anything you want by creating an image that contains the colors you want, and then installing a shape layer as a mask layer to that image's layer, and animating changes to the path installed in the shape layer. 您可以通过创建包含所需颜色的图像,然后将形状图层作为遮罩层安装到该图像的图层,并为形状图层中安装的路径设置动画,来完成您想要的任何操作。

I've used a technique like that to create various sorts of "wipe" transitions that reveal an image. 我使用了这样的技术来创建各种“擦除”过渡,揭示图像。 See the thread below for info and working code showing how to create a "Clock wipe", which is almost exactly what you need: 请参阅下面的主题,了解如何创建“时钟擦除”的信息和工作代码,这几乎正是您所需要的:

How do you achieve a "clock wipe"/ radial wipe effect in iOS? 你如何在iOS中实现“时钟擦除”/径向擦除效果?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM