执行任务(iOS中)动画结束后, [英] Perform a task (in iOS) after animation has finished

查看:588
本文介绍了执行任务(iOS中)动画结束后,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这行code的:

So I have this line of code:

[的tableView setContentOffset:点动画:是];

和我想要的动画结束后,运行另一块code的。我的尝试是扔动画code(setContentOffset)在一个单独的方法,并使用调用它:

and I want to run another piece of code after the animation ends. My attempt was to throw the animating code (setContentOffset) in a separate method and calling it using:

[自performSelectorOnMainThread:@selector(scrollMethod :) withObject:发件人waitUntilDone:YES];

的问题是,该方法将立即返回,不是动画完成后,即使waitUntilDone是YES,但显然这是如何动画作品。

The problem is that the method returns immediately, not after the animation is finished, even though waitUntilDone is YES, but apparently that is how animation works.

我知道,我可以使用线程在等待,但它不干净,所以我只会用它作为最后的手段。 (也许,如果我知道这需要滚动动画的情况发生的时候,我会用这个。)

I know that I can use thread waiting but it is not clean, so I will only use it as a last resort. (Maybe I would use this if I know the time it takes the scrolling animation to happen.)

如何去这方面有任何想法,欢迎。

Any ideas on how to go about this are welcome.

(PS中的情况是这样的:我表示酥料饼,这将显示完美当没有键盘,但是,如果该键盘是可见的,所述酥料饼的高度收缩有时仅所以之前它减少到几乎边框。显示酥料饼,我要向上滚动视图,使酥料饼从来没有在键盘弹出。)

(P.S. The scenario is this: I am showing a popover, which is displayed perfectly when there is no keyboard, however, if the keyboard is visible, the popover's height shrinks which sometimes reduces it to almost border only. So just before showing the popover, I want to scroll the view upwards so that the popover never pops in the keyboard.)

推荐答案

尝试使用此方法:

[UIView animateWithDuration:0.6f
                      delay:0.0f
                    options:UIViewAnimationOptionCurveEaseOut
                 animations:^{
                     // Do your animations here.
                 }
                 completion:^(BOOL finished){
                     if (finished) {
                         // Do your method here after your animation.
                     }
                 }];

这篇关于执行任务(iOS中)动画结束后,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆