Alex Rivera | Logout

How do you move a CALayer instantly (without animation)

Asked 2008-10-22T15:40:40.840
83

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.

Edit
Report

2 Answers

24

You can also use the convenience function

[CATransaction setDisableActions:YES] 

as well.

Note: Be sure to read the comments by Yogev Shelly to understand any gotchas that could occur.

answered 2011-09-13T23:20:26.660
15

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 use setAnimationDuration with a value of 0.0.

[CATransaction begin];
[CATransaction setAnimationDuration:0.0];
layer.position = CGPointMake(x, y);
[CATransaction commit];
answered 2013-05-05T04:04:42.863

Your Answer