我尝试使用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];

最佳答案

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

就是说,我相信您可以将更改提交到UIView动画块内视图的主后备层。

除了视图支持层以外的CALayers不能使用UIView块动画进行动画处理,但是它们确实支持许多属性的“隐式动画”。如果更改不是视图支持层的层的可设置动画的属性,则系统将使用默认动画设置(定时和步调)应用该更改。您可以使用CATransaction调用来更改那些隐式动画的设置,或进行更改而无需设置动画。

关于ios - 如何为CALayer使用基于块的动画?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32534294/

10-14 22:30
查看更多