5

私は次の簡単なコードを持っています:

[otherClass doMethodOneWhichHasAnimation];

そのアニメーションは0.8秒続きます。ビューコントローラをプッシュするコードが続きます:

SchemeView *schemeView = [[SchemeView alloc] init];
    [self.navigationController pushViewController:schemeView animated:YES];
    [schemeView release];

問題は、それがビューコントローラを待たずにプッシュすることです。私はそれを待たせたいのです。遅延を実行すると、最初のアニメーションの開始を含め、すべてが遅延します。

コードの2番目のビットを実行する前に0.8秒待機させるにはどうすればよいですか?

4

4 に答える 4

14

アニメーションが終わったらプッシュできます

[UIView animateWithDuration:0.8
        animations:^{ 
            // Animation
        } 
        completion:^(BOOL finished){

          // PushView

        }];

<iOS 4以降の場合は、setAnimationDidStopSelectorをご覧ください

また

[self performSelector:@selector(metohodToPushView) withObject:nil afterDelay:0.8];
于 2011-06-13T11:57:01.433 に答える
14

CATransactionアニメーションを作成するメソッドのソースコードを変更せずに、アニメーションの後に完了ブロックを実行するために使用できます。フレームワークとリンクするQuartzCore必要があり、する必要があります#import <QuartzCore/QuartzCore.h>。次に、これを行うことができます:

[CATransaction begin]; {

    [CATransaction setCompletionBlock:^{
        // This block runs after any animations created before the call to
        // [CATransaction commit] below.  Specifically, if
        // doMethodOneWhichHasAnimation starts any animations, this block
        // will not run until those animations are finished.

        SchemeView *schemeView = [[SchemeView alloc] init];
            [self.navigationController pushViewController:schemeView animated:YES];
            [schemeView release];
    }];

    // You don't need to modify `doMethodOneWhichHasAnimation`.  Its animations are
    // automatically part of the current transaction.
    [otherClass doMethodOneWhichHasAnimation];

} [CATransaction commit];
于 2012-02-19T04:47:03.877 に答える
0

この問題を回避するには、アニメーションを実行するための新しいクラスを作成しました。

このクラスは、アニメーションの開始と同期して経過した時間をカウントします。

アニメーションの時間をクラスにフィードすると、アニメーションブロックとクラスカウンターの両方がその数を受け取ります。

カウンターが終了すると、アニメーションも終了したことがわかります。

...すべてランダムで複雑なライブラリなし。

于 2012-02-22T10:59:39.147 に答える
-2

遅延時間間隔でメソッドを呼び出すだけです

お気に入り-

[self performSelector:@selector(delayMethod) withObject:nil afterDelay:1.00];
于 2012-02-23T12:46:09.347 に答える