Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delay while moving CALayer with pan gesture

I use pan gesture to move an image in CALayer. The issue I experience is that the image appears to move with a little delay and does not appear 'stuck' to my finger.

Here is the actual snippet of how I move the layer(facePic is the CALayer):

CGPoint translation =[touche locationInView:self.view];
self.facePic.frame =
CGRectMake(translation.x - self.facePic.frame.size.width/2,
           translation.y - self.facePic.frame.size.height/2,
           self.facePic.frame.size.width,
           self.facePic.frame.size.height);
like image 765
gop Avatar asked Jan 24 '13 09:01

gop


1 Answers

I think you see the result of implicit animation of a layer. If so then there are two options to disable this animation:

  1. use transactions
  2. set layer actions

To use transactions wrap your code with CATransaction

[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
 . . .
[CATransaction commit];

To disable some layer actions you can add this to the layer init, the position animation for example:

aLayer.actions = @{@"position":[NSNull null]}; // FIXED property name
like image 181
voromax Avatar answered Sep 30 '22 14:09

voromax