4

CAKeyframeAnimation でこの問題が発生しています。UIView のレイヤーをアニメーション化した後、UIView をアニメーション化する位置に配置して、ユーザーがこの UIView のボタンを引き続き使用できるようにします。

私は現在このコードを使用しています:

    // Open animation
    CAKeyframeAnimation *openAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.y"];
    openAnimation.fillMode = kCAFillModeForwards;
    openAnimation.duration = .55;
    openAnimation.delegate = self;
    openAnimation.removedOnCompletion = NO;


    openAnimation.values = [NSArray arrayWithObjects:
                            [NSNumber numberWithFloat:0.0],
                            [NSNumber numberWithFloat:58.0],
                            [NSNumber numberWithFloat:48.0], nil];

    openAnimation.keyTimes = [NSArray arrayWithObjects:
                              [NSNumber numberWithFloat:0.0],
                              [NSNumber numberWithFloat:0.62],
                              [NSNumber numberWithFloat:1.0], nil];

    openAnimation.timingFunctions = [NSArray arrayWithObjects:
                                     [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut], 
                                     [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut], nil];

    [locationView.layer addAnimation:openAnimation forKey:@"OPEN_ANIMATION"];

そしてデリゲートメソッド:

- (void)animationDidStop:(CAKeyframeAnimation *)anim finished:(BOOL)flag
{
    locationView.y = -10.0;
}

これは実際には機能しますが、最後に、アニメーションが削除され (UIView レイヤーが元の位置にジャンプして戻る)、デリゲート メソッドを即座に呼び出して終了位置にジャンプするという表示上の不具合が発生しています。

最後の手順は次のように感じます: アニメーションが完了し、アニメーションの最後のフレームをレンダリングし、元の位置に戻り、このフレームをレンダリングし、デリゲート メソッドを呼び出し、uiview を終了位置に配置します。

この表示の不具合を修正するにはどうすればよいですか?

4

1 に答える 1

4

アニメーションをレイヤーに追加する前に、終了位置を設定してみます。position関数のレイヤーを変更していると仮定すると、animationDidStopこれらの行を変更します

// Set end position for layer

CAKeyframeAnimation *openAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position.y"];
openAnimation.fillMode = kCAFillModeBackwards;
//openAnimation.removedOnCompletion = NO;

// The rest of your code

キーパスと同じレイヤーのプロパティを設定する必要があるため、ここではキーパスが重要です (この場合はposition)。そうしないと、fillmode が正しく機能しません。

于 2011-11-23T17:50:58.627 に答える