jowie
jowie

Reputation: 8068

How can I stop CALayers from animating?

I've created a bunch of sublayers within my view, populating each one with a graphic, so effectively they are sprites. However, when I call [lineLayer setValue:[NSNumber numberWithFloat:0.5] forKeyPath:@"transform.scale"] it appears to 'tween' to that size instead of just appearing at the new scale.

Is there any way of switching off this behaviour? I just want to change the scale directly.

Thanks!

:-Joe

Upvotes: 1

Views: 3650

Answers (2)

Christopher Schardt
Christopher Schardt

Reputation: 431

Also, for cleanliness' sake, use this line:

[CATransaction setDisableActions:YES];  

in place of this one:

[CATransaction setValue:(id)kCFBooleanTrue
               forKey:kCATransactionDisableActions];

Upvotes: 12

jowie
jowie

Reputation: 8068

Ahhh I just answered my own question... I keep doing that on here!

From the help:

You can temporarily disable layer actions when changing layer property values by setting the value of the transaction’s kCATransactionDisableActions to true. Any changes made during the scope of that transaction will not result in an animation occurring. Listing 2 shows an example that disables the fade animation that occurs when removing aLayer from a visible layer-tree.

[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue
                 forKey:kCATransactionDisableActions];
[aLayer removeFromSuperlayer];
[CATransaction commit];

Upvotes: 12

Related Questions