문제

StackoverFlow에 대한 도움 덕분에 현재 CashApelayer의 경로를 애니메이션으로 만들어 이동 스프라이트에서 화면의 다른 이동 지점으로 가리키는 삼각형을 만듭니다.

애니메이션이 완료되면 삼각형이 화면에서 사라집니다. 이 코드는 각 스프라이트에 대해 2 초마다 발사되기 때문에 매우 짧은 지속 시간을 사용하고 있습니다. 결과는 빨간색 삼각형 트랙이 올바르게 이루어 지지만 빠르게 깜박이거나 전적으로 존재하지 않습니다. 기간을 크랭크하면 삼각형이 더 오래 머무를 수 있습니다.

삼각형을 화면에 유지하기 위해 무엇을 할 수 있습니까? tovalue) 방법이 다시 호출 될 때까지 그 자리에서 다음 지점까지 애니메이션을 할 때까지? 나는 제거 된 정액과 제거를 설정하려고 시도했지만 아무 소용이 없었다.

아래 코드 :

-(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의 기본값은 "kcafillmoderemoved"이며 완료되면 애니메이션을 제거합니다.

이 작업을 수행:

connectorAnimation.fillMode = kCAFillModeForwards;

이렇게해야합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top