5

我有简单的代码:

[otherClass doMethodOneWhichHasAnimation];

该动画持续0.8秒。随后是推送视图控制器的代码:

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

问题是,它无需等待即可推动视图控制器,我希望它等待。做延迟只会延迟整个事情,包括开始的第一个动画。

我怎样才能让它在运行第二段代码之前等待 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 回答