Question

Merci à l'aide sur StackOverflow, je suis actuellement animaient un chemin dans CAShapeLayer pour former un triangle qui pointe d'un sprite passer à un autre point mobile à l'écran.

Une fois l'animation terminée, le triangle disparaît de l'écran. J'utilise des durées très courtes, car ce code est tiré tous les 0,1 de seconde pour chacun des sprites. Le résultat est le triangle rouge suit correctement, mais il clignote rapidement ou n'est pas là tout à fait. Quand je la manivelle la durée, je peux le voir le triangle rester plus longtemps.

Que puis-je faire pour obtenir le triangle pour rester sur l'écran, avec son chemin courant (le tovalue) jusqu'à ce que la méthode est appelée à nouveau pour animer de l'endroit à l'autre endroit? J'ai essayé de régler la removedOnCompletion et removeAllAnimations, mais en vain.

code ci-dessous:

-(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;

}
Était-ce utile?

La solution

La question est la fillMode sur votre animation. La valeur par défaut pour fillMode est « kCAFillModeRemoved » qui supprimera l'animation une fois rempli.

Pour ce faire:

connectorAnimation.fillMode = kCAFillModeForwards;

Cela devrait le faire.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top