CAShapeLayer路径在动画后消失 - 需要它留在同一个地方

KLC*_*KLC 4 iphone core-animation core-graphics cashapelayer

感谢StackOverflow的一些帮助,我目前正在动画CAShapeLayer中的一个路径来制作一个三角形,从移动的精灵指向屏幕上的另一个移动点.

动画完成后,三角形将从屏幕上消失.我使用的持续时间非常短,因为每个精灵每秒.1秒会触发此代码.结果是红色三角形轨道正确,但它快速闪烁或完全没有.当我加速持续时间时,我可以看到三角形停留的时间更长.

我可以做些什么来让三角形保持在屏幕上,使用它的当前路径(tovalue),直到再次调用该方法从该点到下一个点的动画?我尝试设置removedOnCompletion和removeAllAnimations,但无济于事.

代码如下:

-(void)animateConnector{

//this is the code that moves the connector from it's current point to the next point
//using animation vs. position or redrawing it

    //set the newTrianglePath
    newTrianglePath = CGPathCreateMutable();
    CGPathMoveToPoint(newTrianglePath, nil, pointGrid.x, pointGrid.y);//start at bottom point on grid
    CGPathAddLineToPoint(newTrianglePath, nil, pointBlob.x, (pointBlob.y - 10.0));//define left vertice
    CGPathAddLineToPoint(newTrianglePath, nil, pointBlob.x, (pointBlob.y + 10.0));//define the right vertice
    CGPathAddLineToPoint(newTrianglePath, nil, pointGrid.x, pointGrid.y);//close the path
    CGPathCloseSubpath(newTrianglePath);
    //NSLog(@"PointBlob.y = %f", pointBlob.y);

    CABasicAnimation *connectorAnimation = [CABasicAnimation animationWithKeyPath:@"path"];`enter code here`
    connectorAnimation.duration = .007; //duration need to be less than the time it takes to fire handle timer again
    connectorAnimation.removedOnCompletion = NO;  //trying to keep the the triangle from disappearing after the animation
    connectorAnimation.fromValue = (id)trianglePath;  
    connectorAnimation.toValue = (id)newTrianglePath;
    [shapeLayer addAnimation:connectorAnimation forKey:@"animatePath"];


    //now make the newTrianglePath the old one, so the next animation starts with the new position 2.9-KC
    self.trianglePath = self.newTrianglePath;

}
Run Code Online (Sandbox Code Playgroud)

bst*_*ood 5

问题是动画上的fillMode.fillMode的默认值是"kCAFillModeRemoved",它将在完成时删除动画.

做这个:

connectorAnimation.fillMode = kCAFillModeForwards;
Run Code Online (Sandbox Code Playgroud)

这应该做到这一点.