我有一个CALayer layer
,我想用CADisplaylink移动它。喜欢:
layer.center=CGPointMake(layer.center.x + 10, layer.center.y + 10);
但是我无法使用center
或position
作为图层。这是我的问题,我想让它像uiimageview一样移动。
答案 0 :(得分:13)
要移动图层,请尝试使用此方法
-(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"];
}