为什么有些动画的属性中设置动画块外没有生效? [英] Why do some animatable properties set outside an animation block not take effect?

查看:126
本文介绍了为什么有些动画的属性中设置动画块外没有生效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一点code那是这样的:

I have a bit of code that goes like this:

//up till now someButton's alpha was 1
someButton.alpha = 0;
[UIView animateWithDuration:.25
                      delay:0.0
                    options:kMaskEaseOut
                 animations:^ {
                     someButton.alpha = 1;
                 }
                 completion:^ (BOOL finished){}];

问题是动画开始之前someButton的alpha没有设置为0,即没有任何视觉上发生。现在,如果我注释掉整个动画块它的确会someButton的alpha设置为0。另外,如果我这样做:

The problem is someButton's alpha isn't set to 0 before the animation begins, ie nothing visually happens. Now, if I comment out the entire animation block it will indeed set the alpha of someButton to 0. Also, if I do this:

    [UIView animateWithDuration:0
                      delay:0.0
                    options:kMaskEaseOut
                 animations:^ {
                     someButton.alpha = 0;
                 } completion:^ (BOOL finished){
                     [UIView animateWithDuration:.25
                                           delay:0.0
                                         options:kMaskEaseOut
                                      animations:^ {
                                          someButton.alpha = 1;
                                      }
                                      completion:^ (BOOL finished){}];
                 }];

这是一种愚蠢的

它工作正常(我开始一个0长度的动画动画后)。

it works fine (I start the animation after a 0 length animation) which is kind of silly.

推荐答案

检查<一href=\"http://developer.apple.com/library/ios/#documentation/windowsviews/conceptual/viewpg_iphoneos/animatingviews/animatingviews.html\"相对=nofollow>这个,特别是部分动画(他们有比你一个类似的例子: hideShowView )。这种行为差异的原因你的两个codeS是该动画在存在的另一个线程,发生的立即

Check this, specially the section Animations(they have a similar example than yours: hideShowView). The reason of this difference of behavior in your two codes is that animation are occuring in another thread that takes place immediately.

 //up till now someButton's alpha was 1
 someButton.alpha = 0;
 [UIView animateWithDuration:.25
                          delay:0.0
                        options:kMaskEaseOut
                     animations:^ {
                         someButton.alpha = 1;
                     }
                     completion:^ (BOOL finished){}];
 NSLog(@"%d", someButton.alpha); // will display 1 not 0

我想你可以稍微耽误你的动画,如果你不想注释掉动画(在你的第二个code源0延迟的动画)。

I think you could slightly delay your animation if you don't want to comment out your animation (the animation with 0 delay in your second code source).

这篇关于为什么有些动画的属性中设置动画块外没有生效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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