1

How can I add a sublayer to a CALayer without animation? Usually when you add one it "fades in" and when you remove one it "fades out".

How to supress the animation?

Kristina Brooks
  • 15,329
  • 28
  • 106
  • 178

3 Answers3

6

Have you tried this:

[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue
                 forKey:kCATransactionDisableActions];
[layer addSublayer:sublayer];
[CATransaction commit];

from the Apple docs?

Matt Long
  • 24,295
  • 4
  • 72
  • 99
2

You can also suppress implicit layer addition animations by setting the actions dictionary on the superlayer, like I describe in this answer:

NSMutableDictionary *newActions = [[NSMutableDictionary alloc] initWithObjectsAndKeys:[NSNull null], @"sublayers", nil];
superlayer.actions = newActions;
[newActions release];
Community
  • 1
  • 1
Brad Larson
  • 169,393
  • 45
  • 393
  • 567
0

You can use

[CATransaction setAnimationDuration:0.0f];
Ziad Tamim
  • 340
  • 6
  • 17