本文介绍了移动CALayer的(添加动画)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以及我有一个CALayer的,我想移动它,用CADisplaylink。这样的:

well I have a CALayer layer and I would like to move it, with a CADisplaylink. Like :

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

但我不能使用中心位置的layer.Here是我的问题,我想让它动就像是一个UIImageView。

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.

推荐答案

要移动图层尝试使用此方法。

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

这篇关于移动CALayer的(添加动画)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 08:51