I'm trying to drag a CALayer in an iOS app.
As soon as I change its position property it tries to animate to the new position and flickers all over the place:
layer.position = CGPointMake(x, y)
How can I move CALayers instantly? I can't seem to get my head around the Core Animation API.
You can also use the convenience function
as well.
Note: Be sure to read the comments by Yogev Shelly to understand any gotchas that could occur.
As others have suggested, you can use
CATransaction
.The problem comes arises because CALayer has a default implicit animation duration of 0.25 seconds.
Thus, an easier (in my opinion) alternative to
setDisableActions
is to usesetAnimationDuration
with a value of0.0
.Combining previous answers here for Swift 4, to clearly make the animation duration explicit...
Usage...
You want to wrap your call in the following:
Swift 3 Extension :
Usage :