【发布时间】:2017-02-02 16:34:53
【问题描述】:
我有一个圆弧,并改变颜色三遍。我在 SO 上使用了一个示例来帮助我入门:Change CALayer color while animating
这个例子有效,但是颜色是红色,然后是绿色,然后是蓝色。我希望它们是绿色,橙色,然后是红色。我试图弄清楚他是如何在代码中改变颜色的,这让我很困惑:
for (NSUInteger i = 0; i < 3; i++)
{
CAShapeLayer* strokePart = [[CAShapeLayer alloc] init];
strokePart.fillColor = [[UIColor clearColor] CGColor];
strokePart.frame = tutorialCircle.bounds;
strokePart.path = tutorialCircle.path;
strokePart.lineCap = tutorialCircle.lineCap;
strokePart.lineWidth = tutorialCircle.lineWidth;
// These could come from an array or whatever, this is just easy...
strokePart.strokeColor = [[UIColor colorWithHue: i * portion saturation:1 brightness:1 alpha:1] CGColor];
所以我相信这条线正在改变颜色:
strokePart.strokeColor = [[UIColor colorWithHue: i * portion saturation:1 brightness:1 alpha:1] CGColor];
我的目标是将这些颜色调整为绿橙红,而不是红绿和蓝。
谢谢
编辑:
这是part的值:
const double portion = 1.0 / ((double)3);
【问题讨论】:
-
portion的值是多少? -
它正好等于 1/3 所以 const double part = 1.0 / ((double)3);
-
它等于 1/3 或 0.333333,对吧?
-
是的,我的错我刚刚发现
标签: ios objective-c calayer