CAShapeLayerパスは、アニメーションの後に消える - それは同じ場所に滞在する必要があります
-
19-09-2019 - |
質問
StackOverflowの上のいくつかの助けのおかげで、私は現在、画面上の別の移動のポイントに移動するスプライトから指し示す三角形を作るために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;
}
解決
問題がアニメーションにFILLMODEです。 FILLMODEのデフォルトは、完成したときにアニメーションを削除します「kCAFillModeRemoved」です。
これを行います:
connectorAnimation.fillMode = kCAFillModeForwards;
これはそれを行う必要があります。
所属していません StackOverflow