2010-02-10 24 views
4

感谢在StackOverflow上的一些帮助,我目前正在动画CAShapeLayer中的一个路径,以创建一个从移动的精灵指向屏幕上另一个移动点的三角形。CAShapeLayer路径在动画后消失 - 需要它留在同一个地方

动画完成后,三角形从屏幕上消失。我使用的持续时间很短,因为这些代码每次都会以每秒0.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; 

} 
+0

我的回答对你有帮助吗?如果是这样,你能标记它吗? – bstahlhood 2010-08-30 18:15:24

回答

5

的问题是,在你的动画在fillMode。 fillMode的默认值是“kCAFillModeRemoved”,它将在完成后删除动画。

这样做:

connectorAnimation.fillMode = kCAFillModeForwards; 

这应该这样做。

+0

感谢你的帮助,我也出来了 – 2013-12-28 09:07:55