由于在计算器上一些帮助,我目前在动画一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;

}
有帮助吗?

解决方案

这个问题是在你的动画在fillMode。对于在fillMode默认为“kCAFillModeRemoved”建成后,将删除你的动画。

这样做:

connectorAnimation.fillMode = kCAFillModeForwards;

此应该这样做。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top