简体   繁体   English

移动CALayer(添加动画)

[英]move a CALayer (add animation)

well I have a CALayer layer and I would like to move it, with a CADisplaylink. 好吧,我有一个CALayer layer ,我想用CADisplaylink移动它。 Like : 喜欢 :

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

but I can't use center or position for the layer.Here is my problem, I want to make it move like it was a uiimageview. 但是我不能使用图层的centerposition 。这是我的问题,我想让它像uiimageview一样移动。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM