Delay when moving CALayer using pan gestures

I use a movement gesture to move the image in CALayer. The problem I am experiencing is that the image does not seem to move with a slight delay and does not appear “stuck” on my finger.

Here is the actual snippet of how I move the layer (facePic is 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);
+5
source share
1 answer

I think you see the result of an implicit layer animation. If so, there are two options for disabling this animation:

  • use transactions
  • set layer actions

To use transactions, wrap your code with CATransaction

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

, init, , :

aLayer.actions = @{@"position":[NSNull null]}; // FIXED property name
+9

All Articles