我试图展示一个简单的点移动。我设置了一个图层,设置了边界、位置和颜色,然后使用 CAAnimation 显示它在移动
CALayer *l = [CALayer layer];
l.bounds = CGRectMake(0,0,20,20);
l.position = CGPointMake(x,y);
l.cornerRadius = 10;
l.backgroundColor = [UIColor blueColor].CGColor;
[self.theView.layer addSublayer:l];
CABasicAnimation *anim1 = [CABasicAnimation animationWithKeyPath:@"position"];
anim1.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
CGPoint to = CGPointMake(x+dx, y+dy);
anim1.fromValue = [l valueForKey:@"position"];
anim1.toValue = [NSValue valueWithCGPoint:to];
l.position = to;
anim1.duration = 3.0;
当我运行它时,我看到两个蓝色圆圈在移动。我想看到一个圆圈从 (x,y) 移动到 (x+dx,y+dy)。有人可以告诉我我做错了什么吗?
谢谢