1
votes

I attempted to infinitely pulse a gradient from transparent to opaque using UIView's block animation. The final result is the gradient remains at full opacity with no animation. Is it even possible to animate CALayer's with the block style or must I use old-school series of statements?

_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

1 Answers

0
votes

UIView has block-based animations. CALayers do not. You have to use the various forms of CAAnimation to animate a CALayer.

That said, I believe that you CAN submit changes to a view's primary backing layer inside a UIView animation block.

CALayers other than a view's backing layer can't be animated with UIView block animation, but they do support "implicit animation" of many properties. If you change an animatable property of a layer that isn't a view backing layer, the system applies that change with default animation settings (timing and pacing). You can use CATransaction calls to alter the settings of those implicit animations, or make the change occur without animating.