如何为CALayer使用基于块的动画?

时间:2015-09-12 01:38:32

标签: ios cocoa-touch animation uiview calayer

我试图使用UIView的块动画无限地将渐变从透明到不透明。最终结果是渐变保持完全不透明度而没有动画。是否有可能使用块样式为CALayer设置动画或者我是否必须使用旧式系列语句?

_pulsingLight = [CAGradientLayer layer];
_pulsingLight.colors = @[(id)([UIColor colorWithWhite:1.0 alpha:kPulsingLightStartAlpha].CGColor),
                         (id)([UIColor colorWithWhite:1.0 alpha:kPulsingLightStopAlpha].CGColor)];
_pulsingLight.opacity = 0.0;
[self.layer insertSublayer:_pulsingLight below:_anotherView.layer];
[UIView animateWithDuration:kPulsingLightHalfLife
                      delay:0.0
                    options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
                 animations:^{
                   _pulsingLight.opacity = 1.0;
                 }
                 completion:nil];

1 个答案:

答案 0 :(得分:1)

UIView具有基于块的动画。 CALayers没有。您必须使用各种形式的CAAnimation来设置CALayer的动画。

那就是说,我相信您可以在UIView动画块中提交视图主要支持层的更改。

除了视图的支持图层之外的CALayers无法使用UIView块动画进行动画处理,但它们确实支持许多属性的“隐式动画”。如果更改不是视图背图层的图层的可动画属性,系统会将该更改应用于默认动画设置(计时和调步)。您可以使用CATransaction调用来更改这些隐式动画的设置,或者在没有动画的情况下进行更改。

相关问题