You need to animate the shadowOffset of the layer using CAAnimation. Here is an example of how to increase shadowOffset when moving an object. This example uses UIButton.
In the M file, I call the animation on the button with the IBAction buttons.
-(IBAction)shadowGrow:(id)sender { CABasicAnimation *shadowGrow = [CABasicAnimation animationWithKeyPath:@"shadowRadius" ]; shadowGrow.delegate = self; [shadowGrow setFromValue:[NSNumber numberWithFloat:3.0]]; [shadowGrow setToValue:[NSNumber numberWithFloat:20.0]]; [shadowGrow setDuration:1.0f]; shadowGrow.autoreverses = YES; CABasicAnimation *move = [CABasicAnimation animationWithKeyPath:@"transform.translation.x" ]; move.delegate = self; [move setFromValue:[NSNumber numberWithFloat:0]]; [move setToValue:[NSNumber numberWithFloat:50]]; [move setDuration:1.0f]; move.autoreverses = YES;
One thing to remember with CoreAnimation is that when animating such properties, they return to their value from the very beginning, unless you set these values ββafter the animation finishes in the CAAnimation delegate method.
- (void) animationDidStop:(NSString *)theAnimation finished:(NSNumber *)finished context:(void *)context
See below for more information on the animation properties of CALayer.
CALayer and CIFilter Animation Properties
source share