Pergunta

Graças a alguma ajuda no StackOverflow, atualmente estou animando um caminho no Cashapelyer para fazer um triângulo que aponta de um sprite em movimento para outro ponto de movimento na tela.

Depois que a animação é concluída, o triângulo desaparece da tela. Estou usando durações muito curtas porque esse código está sendo disparado a cada .1 de segundo para cada um dos sprites. O resultado é que o Triângulo Vermelho rastreia corretamente, mas rapidamente pisca ou não está completamente lá. Quando eu acelero a duração, posso ver o triângulo ficar mais tempo.

O que posso fazer para fazer com que o triângulo permaneça na tela, com o caminho atual (o tovalue) até que o método seja chamado novamente para animar do local para o próximo local? Tentei definir o RemovedOnCompletion e Removeallanimations, mas sem sucesso.

Código abaixo:

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

}
Foi útil?

Solução

O problema é o modo de enchimento em sua animação. O padrão para o FillMode é "KcafillModeReMoved", que removerá sua animação quando concluído.

Fazem isto:

connectorAnimation.fillMode = kCAFillModeForwards;

Isso deve servir.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top