UIView的animateWithDuration立即返回 [英] UIView animateWithDuration returns immediately

查看:211
本文介绍了UIView的animateWithDuration立即返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图动画嵌入在一个UIView的标签。

I'm trying to animate a label embedded in a UIView.

这是code:

-(void)displayText:(NSString*)text {


[label setText:text];


[UIView animateWithDuration:5.0
                      delay:0.0
                    options:UIViewAnimationOptionCurveEaseIn
                 animations:^{
                     [labelView setAlpha:1.0];
                 }
                 completion:nil
 ];

[UIView animateWithDuration:5.8
                      delay:0.0
                    options:UIViewAnimationOptionCurveEaseIn
                 animations:^{
                     [labelView setAlpha:0.0];
                 }
                 completion:nil
 ];
}

要验证,该方法被调用时,我设置一个断点。

To verify, the method is called, i set a breakpoint.

通话立刻返回,但只显示动画的结尾。

The calls return immediatly but only the end of animations is displayed.

我有线了UIView到控制器。

I wired the UIView to the controller.

请帮助,我卡住了。

在此先感谢!
帕特里克

Thanks in advance ! Patrick

推荐答案

正确

在动画的看法是这样的动画片实际上并不在屏幕上发生,直到runloop的下一阶段(即一旦你的方法返回)。

When you animate views like this the animation doesn't actually happen on screen until the next pass of the runloop (i.e. once your method returns).

UIView的合并将被连续编程的动画。

UIView will coalesce animations that are programmed sequentially.

使用完毕块褪色退了出去。在code看上去有些奇怪,但它的伟大工程!

Use the completion block to fade back out. The code looks a bit odd but it works great!

[UIView animateWithDuration:5.0
                      delay:0.0
                    options:UIViewAnimationOptionCurveEaseIn
                 animations:^{
                     [labelView setAlpha:1.0];
                 }
                 completion:^(BOOL completed){
                     [UIView animateWithDuration:5.8
                                           delay:0.0
                                         options:UIViewAnimationOptionCurveEaseIn
                                      animations:^{[labelView setAlpha:0.0];}
                                      completion:nil];
                 }];

在响应您的意见:

该动画将无法启动,直到runloop在下次运行。他们将无法启动,直到您的应用程序完成的是什么做的。如果在循环中等待,您将有同样的问题,也冻结您的接口。考虑使用单独的标签,每个字母,并添加一个逐步更大的延迟每个动画。所有这些动画指令会被立即排队,然后发挥出在接下来的然而,许多秒的过程。想象一下,你就像一个电影导演,你告诉每个演员什么在接下来的现场做。然后,当每个人都知道该怎么做,你坐下来,大喊行动看着这一切发挥出来。

The animations won't start until the next run of the runloop. They won't start until your app finishes what its doing. If you wait in the loop you will have the same problem and also freeze up your interface. Consider using individual labels for each letter, and add a progressively bigger delay for each animation. All these animation instructions will be queued up at once and then played out over the course of the next however many seconds. Imagine you are like a movie director, you tell each actor what to do in the next scene. Then, once everyone knows what to do you sit back and yell "action" and watch it all play out.

这篇关于UIView的animateWithDuration立即返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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