krb
krb

Reputation: 16325

Add a sublayer to a CALayer without animation?

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?

Upvotes: 1

Views: 2492

Answers (3)

Ziad Tamim
Ziad Tamim

Reputation: 350

You can use

[CATransaction setAnimationDuration:0.0f];

Upvotes: 0

Brad Larson
Brad Larson

Reputation: 170319

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];

Upvotes: 2

Matt Long
Matt Long

Reputation: 24466

Have you tried this:

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

from the Apple docs?

Upvotes: 6

Related Questions