【问题标题】:move a CALayer (add animation)移动 CALayer(添加动画)
【发布时间】:2012-01-09 02:57:24
【问题描述】:

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

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

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

【问题讨论】:

  • 为什么不能使用中心或位置?为什么不直接换帧?

标签: iphone xcode animation uiimageview calayer


【解决方案1】:

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

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

【讨论】:

  • 但是用这种方法是不可能检测到碰撞的。因为我想让图层发生碰撞之后:/
  • @jeanbernard 不,它仍然完全可以检测到与屏幕上任何其他对象的碰撞 - 看看 CALayer.presentationLayer
  • 嗯,我有点难以理解我们如何检测与 CABasicAnimation 的碰撞,你能解释一下什么是 CALayer.presentationLayer
猜你喜欢
  • 2011-11-05
  • 1970-01-01
  • 2010-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-28
  • 1970-01-01
相关资源
最近更新 更多