6

ビューをアニメーション化するのは簡単です。

[UIView animateWithDuration:1.0
                     animations:^{theView.center = newCenter; theView.alpha = 0;}
                     completion:^(BOOL finished){
                         [theView removeFromSuperview];
                     }];

問題は、サブビューとして追加するときに、フェードインして、すでに動いているように見せたいということです。現在、すぐに表示され、移動してフェードアウトします。

そのため、最初のアルファをゼロに設定し、移動中にすばやくフェードしてから、フェードアウトする必要があります。これはUIViewアニメーションで可能ですか?2つの競合するアニメーションブロックを同じオブジェクトで動作させることはできませんか?

4

2 に答える 2

13

あなたがする必要があるのは、2つのアニメーションを連続して適用することです。このようなもの ::

theView.alpha = 0;
[UIView animateWithDuration:1.0
                 animations:^{
                     theView.center = midCenter;
                     theView.alpha = 1;
                 }
                 completion:^(BOOL finished){
                     [UIView animateWithDuration:1.0
                                      animations:^{
                                          theView.center = endCenter;
                                          theView.alpha = 0;
                                      }
                                      completion:^(BOOL finished){
                                          [theView removeFromSuperview];
                                      }];
                 }];

したがって、最初の1秒間は移動中に表示され、次の1秒間はフェードアウトします。

お役に立てれば

于 2013-02-08T19:27:21.517 に答える
2

最初のalpha=0をアニメーションブロックの外側に配置します。

theView.alpha = 0;
[UIView animateWithDuration:1.0
                 animations:^{
                     theView.center = newCenter; 
                     theView.alpha = 1;
                 }
                 completion:^(BOOL finished){
                     // Do other things
                 }];
于 2013-02-08T19:24:20.393 に答える