Search code examples
iphoneioscore-animation

Why changing values of a CAGradientLayer causes an "automatic" animation? And how can I avoid it?


Possible Duplicate:
How to prevent CALayer from implicit animations?

I'm using a CAGradientLayer as a layer mask for an UIView. The intention is to have the possibility of showing only a part of the UIView and, reacting to user input, change the part of the view that is visible by modifying the CAGradientLayer.

All of this works fine, however I have encountered one issue: To change the part of the UIView that is visible, I modify the values of the following properties of the CAGradientLayer:

startPoint endPoint locations

I change these values outside of an animation block, however the change is animated in the screen. It looks like it is executed with a default, short animation (maybe one second long, it is difficult to tell).

My question is, why the change is being done animated? and how can I prevent the animation? (In fact I would like to have an animation, but controlled by myself, not this default one).

As an additional observation, I know that all those properties (startPoint, endPoint and locations) are flagged as animatable, but my understanding is that this only means that they can be set inside an animation block to get the change animated.


Solution

  • Many of the animatable properties have default animations. When you set them, the default animation happens.

    You can override the default animation by setting the property in an animation block. Any time you change a property in an animation block, any previous animations for that property are replaced by your new animation.