Can I change a strokeEnd property without animation? Can I change a strokeEnd property without animation? ios ios

Can I change a strokeEnd property without animation?


The approach you describe of setting the layer's strokeEnd action to NSNull works but it's a bit of a sledgehammer. When you do that you kill implicit animation of the strokeEnd property of your layer forever.

If that's what you want, that's ok. However, I tend to prefer using the second approach that David Rönnqvist lists in the answer you linked: Making your layer change inside a CATransaction begin/commit block. Here is the code for that from David's answer (which is excellent, as his posts always are).

[CATransaction begin];[CATransaction setDisableActions:YES];// change your property here yourShapeLayer.strokeEnd = 0.7;[CATransaction commit]; // animations are disabled until here...

That code is in Objective-C. Translating it to Swift isn't too bad:

CATransaction.begin()CATransaction.setDisableActions(true)yourShapeLayer.strokeEnd = 0.7CATransaction.commit()


I've found the problem. This solves it:

circle.actions = ["strokeEnd" : NSNull()]

More info can be found here: Change CAShapeLayer without Animation