I want to set the strokeEnd
property of a CAShapeLayer
without the default animation, with no animation at all. I've looked around to try to find how to do this but everything seems to be about how to animate properties.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- back button text does not change
- iOS (objective-c) compression_decode_buffer() retu
- how to find the index position of the ARRAY Where
相关文章
- 现在使用swift开发ios应用好还是swift?
- TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- How can I add media attachments to my push notific
- didBeginContact:(SKPhysicsContact *)contact not in
- Custom Marker performance iOS, crash with result “
- Converting (u)int64_t to NSNumbers
You can do something like the following:
This will make it so it won't animate for the property. You could also specify additional properties to not animate by adding them to this:
In Core Animations terminology, a more general term for an animation is an "action". You can for example see that the
CAAnimation
conforms to theCAAction
protocol. You also see the terminology "action" used when disabling them (disabling the animations).There are many different ways of changing the actions of a layer. Many of them are documented pretty well in the discussion of the
actionForKey:
documentation onCALayer
(excerpt below). Some of them are more relevant when subclassing (and you can also overrideactionForKey:
in your subclass to add more implicit actions for new keys.The two ways that are most interesting when you want to disable animation are (two different because they are used for slightly different things):
CATransaction
(not mentioned above)[NSNull null]
for the@"strokeEnd"
key in the actions dictionary (number 2 above)Disabling actions
Using a transaction to disable animations is good when you temporarily want to disable actions completely for a number of different properties while still having animations everywhere else. In code it looks something like this:
Changing the actions dictionary
You can permanently change the default animation for one or more keys by modifying the layers action dictionary. Setting
[NSNull null]
means that there should be no animation and that the layer should stop looking elsewhere for a default animation. You can also use this to add animatable properties. Removing an animation using the action dictionary looks something like this:I think a nice solution would be to create a
CABasicAnimation(keyPath: "strokeEnd")
and set the duration to something really small. Here is an example: