CAKeyframeAnimationを使用してUIImageViewを画面上で移動すると、断続的な問題が発生します。UIImageViewの位置は、アニメーションが終了したときに終了する場所のままにしておきたいです。このバグは、特定の開始点と終了点でのみ発生します。ランダムポイントを使用すると、ほとんどの場合正しく機能しますが、約5〜15%の確率で失敗し、アニメーション前の位置に戻ります。この問題は、pathプロパティを使用してCAKeyframeAnimationを使用する場合にのみ発生します。valuesプロパティを使用すると、バグは表示されません。removeOnCompletion = NO、fillMode=kCAFillModeForwardsを設定しています。以下にテストXcodeへのリンクを投稿しました。これがアニメーションを設定するための私のコードです。プロパティusePathがあります。これがYESの場合、バグが発生します。usePathをNOに設定すると、スナップバックのバグは発生しません。
// create the point
CAKeyframeAnimation *moveAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
if (self.usePath) {
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, startPt.x, startPt.y);
CGPathAddLineToPoint(path, NULL, endPt.x, endPt.y);
moveAnimation.path = path;
CGPathRelease(path);
} else {
moveAnimation.values = [NSArray arrayWithObjects:
[NSValue valueWithCGPoint:startPt],
[NSValue valueWithCGPoint:endPt],
nil];
}
moveAnimation.calculationMode = kCAAnimationPaced;
moveAnimation.duration = 0.5f;
moveAnimation.removedOnCompletion = NO;
// leaves presentation layer in final state; preventing snap-back to original state
moveAnimation.fillMode = kCAFillModeForwards;
moveAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
// moveAnimation.delegate = self;
// start the animation
[ball.layer addAnimation:moveAnimation forKey:@"moveAnimation"];
テストプロジェクトをダウンロードして表示するには、テストプロジェクトに移動します(http://www.24x7digital.com/downloads/PathFillModeBug.zip)
[ボールを移動]ボタンをタップして、ボールのアニメーションを開始します。バグが毎回発生する原因となる開始点と終了点をハードコーディングしました。スイッチを使用して、usePathをYESまたはNOに変更します。usePathがYESの場合、スナップバックのバグが表示されます。usePathがNOの場合、スナップバックのバグは表示されません。
SDK 3.1.3を使用していますが、SDK 3.0を使用してこのバグを確認し、SimとiPhoneでバグを確認しました。
これを修正する方法や、何か間違ったことをしている場合のアイデアをいただければ幸いです。ありがとう、マーク。