move a CALayer (add animation)
10,145
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"];
}
Related videos on Youtube
Author by
jean bernard
Updated on June 04, 2022Comments
-
jean bernard about 2 years
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
orposition
for the layer.Here is my problem, I want to make it move like it was a uiimageview. -
jean bernard over 12 yearsbut with this method it's impossible to detect collision.Because after I want to make the layer collide :/
-
mostafa tourad over 12 years@jeanbernard no, it still is completely possible to detect a collision with any other object on the screen - have a look at CALayer.presentationLayer
-
jean bernard over 12 yearswell it is a bit hard for me to understand how can we detect a collision with a CABasicAnimation, and can you explain more what is CALayer.presentationLayer