开发者

Add a sublayer to a CALayer without animation?

开发者 https://www.devze.com 2023-01-08 18:36 出处:网络
How can I add a sublay开发者_Python百科er to a CALayer without animation? Usually when you add one it \"fades in\" and when you remove one it \"fades out\".

How can I add a sublay开发者_Python百科er 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?


Have you tried this:

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

from the Apple docs?


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


You can use

[CATransaction setAnimationDuration:0.0f];
0

精彩评论

暂无评论...
验证码 换一张
取 消