我有一个 CALayer layer
,我想用 CADisplaylink 移动它。例如:
layer.center=CGPointMake(layer.center.x + 10, layer.center.y + 10);
但是我不能使用center
或position
来控制该层。这是我的问题,我想让它像uiimageview
一样移动。
我有一个 CALayer layer
,我想用 CADisplaylink 移动它。例如:
layer.center=CGPointMake(layer.center.x + 10, layer.center.y + 10);
但是我不能使用center
或position
来控制该层。这是我的问题,我想让它像uiimageview
一样移动。
要移动图层,请尝试使用这种方法。
-(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"];
}