사용자가 내 애니메이션 속도를 변경할 수있게하려고합니다. 베 지어 경로를 사용하여 CAKeyframeAnimation을 만들고 있는데 올바르게 표시하고 실행할 수 있습니다. 다른 기간으로 새 애니메이션 경로를 만들어 속도를 변경하려고합니다. 비행기는 처음으로 되돌아갑니다 (나는 아직 고치려고하지 않았습니다). 애니메이션이 속도를 전혀 변경하지 않았을 때 그들이 그려지는 길은 사라집니다. 비행기가 끝나면 다른 곳에서 애니메이션이 일시 중지 된 지점에 나타납니다. 나는 내가 뭘 잘못하고 있는지 전혀 모른다. 내 질문은이 하나의 modifying dynamically the duration of CAKeyframeAnimation과 비슷하지만, OP가 블록을 사용하여 마침내 말하는 것에 대해 이해하지 못합니다. (내가 말할 수있는까지) 목표 위치로 현재 위치에서 애니메이션을 기본 애니메이션과 달리iOS에서 CAKeyframeAnimation 중반 애니메이션의 속도 변경하기
//The first two methods are in a class subclassing UIView
/** Pause each plane's animation */
- (void)pauseAnimation
{
CFTimeInterval pausedTime = [[self layer] convertTime:CACurrentMediaTime() fromLayer:nil];
[self layer].speed = 0.0;
[self layer].timeOffset = pausedTime;
}
/** Resume each plane's animation */
- (void)resumeAnimation
{
CFTimeInterval pausedTime = [[self layer] timeOffset];
[self layer].speed = 1.0;
[self layer].timeOffset = 0.0;
CFTimeInterval timeSincePause = [[self layer] convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime;
for(SEPlane *plane in planes){
plane.planeAnimationPath.speedMultiplier = 5;
[plane.planeAnimationPath beginAnimation:self];
}
//[self layer].beginTime = timeSincePause;
}
//This method is in the class of planeAnimationPath
/** Begin animating plane along given path */
- (void)beginAnimation:(UIView *) view
{
planeAnimation = nil;
// Create animation layer for animating plane
planeAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
planeAnimation.path = [bezierPath CGPath];
planeAnimation.duration = approximateLength/(ANIMATION_SPEED * self.speedMultiplier);
planeAnimation.calculationMode = kCAAnimationPaced;
planeAnimation.fillMode = kCAFillModeForwards;
planeAnimation.rotationMode = kCAAnimationRotateAuto;
planeAnimation.removedOnCompletion = YES;
[planeAnimation setDelegate:self];
// Add animation to image-layer
[imageLayer addAnimation:planeAnimation forKey:animationKey];
// Add image-layer to view
[[view layer] addSublayer:imageLayer];
}
오프셋 문제는 수정되었지만 애니메이션이 완료된 후에도 평면은 계속 그려집니다. 나는 그것을 반복하고 싶지 않다. 한 번 그려라. 내가 한 번만 말해달라고 말하면, 그 비행기가 한 번 반복되고 뒤로 향하는 비행기가 나타난다. 정말 이상합니다. – LunaEques
오류를 발견했습니다. animationKey를 설정하는 것을 잊었습니다. 정말 고맙습니다! – LunaEques
@LunaEques 어떻게 애니메이션 반복 문제를 해결 했습니까? 나도 똑같은 문제를 겪고있어. 감사 – Atrash