Disabling implicit animations in -[CALayer setNeedsDisplayInRect:] Disabling implicit animations in -[CALayer setNeedsDisplayInRect:] ios ios

Disabling implicit animations in -[CALayer setNeedsDisplayInRect:]


You can do this by setting the actions dictionary on the layer to return [NSNull null] as an animation for the appropriate key. For example, I use

NSDictionary *newActions = @{    @"onOrderIn": [NSNull null],    @"onOrderOut": [NSNull null],    @"sublayers": [NSNull null],    @"contents": [NSNull null],    @"bounds": [NSNull null]};layer.actions = newActions;

to disable fade in / out animations on insertion or change of sublayers within one of my layers, as well as changes in the size and contents of the layer. I believe the contents key is the one you're looking for in order to prevent the crossfade on updated drawing.


Swift version:

let newActions = [        "onOrderIn": NSNull(),        "onOrderOut": NSNull(),        "sublayers": NSNull(),        "contents": NSNull(),        "bounds": NSNull(),    ]


Also:

[CATransaction begin];[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];//foo[CATransaction commit];


When you change the property of a layer, CA usually creates an implicit transaction object to animate the change. If you do not want to animate the change, you can disable implicit animations by creating an explicit transaction and setting its kCATransactionDisableActions property to true.

Objective-C

[CATransaction begin];[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];// change properties here without animation[CATransaction commit];

Swift

CATransaction.begin()CATransaction.setValue(kCFBooleanTrue, forKey: kCATransactionDisableActions)// change properties here without animationCATransaction.commit()