1

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

jowie
  • 8,028
  • 8
  • 55
  • 94

2 Answers2

12

Also, for cleanliness' sake, use this line:

[CATransaction setDisableActions:YES];  

in place of this one:

[CATransaction setValue:(id)kCFBooleanTrue
               forKey:kCATransactionDisableActions];
Bo Persson
  • 90,663
  • 31
  • 146
  • 203
  • Good point, I don't know why Apple didn't state it like that in their help! Although this isn't really a separate answer... It should really be added to the other answer. Thanks. – jowie Jan 16 '13 at 12:30
  • Can I just add that you only need that line too. – Lee Probert Mar 18 '13 at 18:15
12

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];
jowie
  • 8,028
  • 8
  • 55
  • 94
  • 2
    As @Bo and @Christopher pointed out elsewhere on this page, the property-setter `[CATransaction setDisableActions:YES];` is a cleaner way to do this. – JaredH Oct 19 '15 at 02:13