1

我对CABasicAnimation主题真的很陌生。如果要将CAShapeLayerx 位置从当前 x 位置动画到特定 x 位置,则应使用以下命令:

    NSLog(@"CABasicAnimation now...");
    CABasicAnimation *layerPositionAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
    [layerPositionAnimation setDuration:0.330];
    [layerPositionAnimation setRemovedOnCompletion: NO];
    [layerPositionAnimation setFillMode: kCAFillModeForwards];
    [layerPositionAnimation setTimingFunction: [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
    [layerPositionAnimation setFromValue:[NSValue valueWithCGPoint:CGPointMake(self.shapeLayer.position.x, self.shapeLayer.position.y)]];
    [layerPositionAnimation setToValue:[NSValue valueWithCGPoint:CGPointMake(14.0, self.shapeLayer.position.y)]];
    [self.shapeLayer addAnimation:layerPositionAnimation forKey:@"layerPositionAnimation"];

在我的例子中,self.shapeLayer 是一个 CAShapeLayer,用作一个简单的蒙版:

    [[overlayTopShadow layer] setMask:self.shapeLayer];  

但是如果动画永远不会发生(x 位置没有改变)怎么办?我在我的代码中做错了什么?有什么建议、想法、例子吗?

非常感谢

4

0 回答 0