移动CALayer(添加动画)

时间:2011-11-29 19:13:04

标签: iphone xcode animation uiimageview calayer

我有一个CALayer layer,我想用CADisplaylink移动它。喜欢:

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

但是我无法使用centerposition作为图层。这是我的问题,我想让它像uiimageview一样移动。

1 个答案:

答案 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"];
}