1

ボタンを座標に移動し、一時停止し、別の座標に移動し、一時停止してから、もう一度移動しようとしています。その後、プロセスは無限に繰り返されます。私が今持っているものは、最後のステップを動かすだけです。

これは私がこれまでに持っているものです(「mover」はUIButton名です):

- (void) firstAnimation {

        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.5];
        [UIView setAnimationDelay:5];
        [UIView setAnimationRepeatCount:-1];
        [UIView setAnimationRepeatAutoreverses:NO];

        CGPoint pos = mover.center;
        pos.y = 200.f;
        pos.x = 169.f;
        mover.center = pos;

        [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(firstAnimation:) userInfo:nil repeats:NO];
        pos.y = 100.f;
        pos.x = 179.f;
        mover.center = pos;

        [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(firstAnimation:) userInfo:nil repeats:NO];
        pos.y = 160.f;
        pos.x = 129.f;
        mover.center = pos;

        [UIView commitAnimations];

}

助けてくれてありがとう

4

3 に答える 3

3

タイマーを使用する必要はありません。アニメーションデリゲートをselfに設定し、animationfinishedメソッドを実装するだけです。

ここで私の答えを参照してください:

無限ループのアニメーション

于 2010-10-13T17:34:26.263 に答える
1

iOS4専用に配送する場合は、ブロックと次の方法を使用することを強くお勧めします。

[UIView animateWithDuration:kAnimationDuration
                      delay:kAnimationDelay
                    options:UIViewAnimationCurveEaseInOut
                 animations:^ {
                     // your animations here.
                 }
                 completion:^(BOOL finished) {
                     // what you want to do upon animation completion here.
                 }];

完了ブロックでは、別のアニメーションをキューに入れることもできます。実際、3つのアニメーションブロックをブロック変数として保存し、それらを上記のメソッドに渡して、3番目が完了するまで次々に実行することができます。次に、プロセスを再開します。

ブロックはあなたの友達です。

于 2010-10-13T18:00:16.423 に答える
0

CoreAnimationキーフレームrepeatCount = HUGE_VALFを使用し、永久ループに設定する方が適しています

于 2010-10-13T17:48:25.493 に答える