天天看点

Animated progress view with CAGradientLayer(带翻译)<待更新>

Animated progress view with CAGradientLayer(带翻译)<待更新>

pretty straightforward. if you parent the view and run it in the simulator you’ll see our view has a horizontal gradient with all the colors in the spectrum.

next, to create the moving effect we can cycle the colors in the <code>colors</code> array and use a layer animation. a single animation will move one color and repeat the process when finished. the next two methods will do the trick.

很简单。如果父视图并运行它在模拟器上你会看到我们的看法与在光谱中所有颜色水平渐变。

接下来,创建我们可以循环中的颜色移动效果<code>的颜色</code>阵列,并使用图层动画。单个动画将移动一个颜色,完成后重复上述过程。接下来的两个方法就可以了。

to add the indication of progress, we can use a simple layer mask to block out portions of our gradient. add the following two properties to your header file:

要添加的进度指示,我们可以用一个简单的图层蒙版来阻挡我们梯度的部分。以下两个属性添加到您的头文件:

be sure to <code>@synthesize</code> and then append the following to your <code>initwithframe:</code>

一定要<code>@synthesize</code>,然后添加以下到您的<code>initwithframe:方法</code>

this creates a zero width mask, covering the entire view. the color of the mask doesn’t matter here but it is required to work properly. now when our <code>progress</code> is updated we want to expand the width of the mask to reflect the value. override the <code>setprogress:</code> method to contain the following:

这将创建一个零宽度面具,覆盖了整个视图。面膜的肤色并不重要,在这里,但它需要正常工作。现在,当我们的<code>进展</code>被更新我们要扩大掩模的宽度,以反映值。重写<code>setprogress:</code>方法包含以下内容:

now when our <code>progress</code> value is set, we make sure it’s within the 0.0 to 1.0 range and invalidate the layout. then in the next call to<code>layoutsubviews</code> we resize the mask based on its new value.

现在,当我们<code>的进展</code>值设置,我们要确保它的0.0至1.0范围内,布局失效。然后到下一次调用<code>layoutsubviews</code>我们调整基于它的新值面具。