移动CALayer(添加动画)

jea*_*ard 8 iphone xcode animation calayer uiimageview

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

layer.center=CGPointMake(layer.center.x + 10, layer.center.y + 10);
Run Code Online (Sandbox Code Playgroud)

但我不能使用centerposition用于图层.这是我的问题,我想让它像uiimageview一样移动.

ber*_*ium 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"];
}
Run Code Online (Sandbox Code Playgroud)