Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

move a CALayer (add animation)

well I have a CALayer layer and I would like to move it, with a CADisplaylink. Like :

layer.center=CGPointMake(layer.center.x + 10, layer.center.y + 10);

but I can't use center or position for the layer.Here is my problem, I want to make it move like it was a uiimageview.

like image 708
jean bernard Avatar asked Nov 29 '11 19:11

jean bernard


1 Answers

To move layer try to use this method

-(void)moveLayer:(CALayer*)layer to:(CGPoint)point{
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
    animation.fromValue = [layer valueForKey:@"position"];
    animation.toValue = [NSValue valueWithCGPoint:point];
    layer.position = point;
    [layer addAnimation:animation forKey:@"position"];
}
like image 100
beryllium Avatar answered Oct 11 '22 09:10

beryllium