This drives me mad. Whenever I change value of CATextLayer.foregroundColor
property the change is animated no matter what I do. For example I have CATextLayer
called layer
which is sublayer of CALayer
superlayer
:
layer.removeAllAnimations()
superlayer.removeAllAnimations()
superlayer.actions = ["sublayers" : NSNull()]
CATransaction.begin()
CATransaction.setAnimationDuration(0)
CATransaction.disableActions()
CATransaction.setValue(kCFBooleanTrue, forKey:kCATransactionDisableActions)
layer.actions = ["foregroundColor" : NSNull()]
layer.actions = ["content" : NSNull()]
layer.foregroundColor = layoutTheme.textColor.CGColor
CATransaction.commit()
And it will still animates! Please help, how can I disable the implicit animations?
The problem is that CATransaction.disableActions()
does not do what you think it does. You need to say CATransaction.setDisableActions(true)
.
And then you can get rid of all the other stuff you're saying, as it is pointless. This code alone is sufficient to change the color without animation:
CATransaction.setDisableActions(true)
layer.foregroundColor = UIColor.redColor().CGColor // or whatever
(You can wrap it in a begin()
/commit()
block if you have some other reason to do so, but there is no need just in order to switch off implicit layer property animation.)