Search code examples
uiviewcore-animation

How to animate UIView.layer.shadow & UIView.center concurrently


I'm having a bit of an issue:

I have a UIView which needs to have two animations done at the same time.

1) I need to animate the .layer.shadowRadius.

2) I need to animate the .center property (move the view from point A to point B).

I would really like to do this the "new" way using UIView animateWithDuration:animations:, but I can't animate the shadow in this method. I have to use CABasicAnimation as of right now.

Is there a way to combine these easily?

thanks


Solution

  • You should create two CABasicAnimations (for the "shadowRadius" and the "position") and configure their to and from values.

    Then create a CAAnimationGroup and set the animations to be an array of your two animations. Now you can configure the duration, timing etc. on the animation group and it will apply to both animations.

    (You add the animation group to the layer that you are animating as it contains the other two animations).