2014年4月24日木曜日

iOS4からのアニメーションはanimateWithDuration: が標準

いままで、Viewのアニメーションは、beginAnimations:を使ってたけど、なんとiOS4からは、ブロック構文をつかったanimateWithDurationが普通なのな。

なぜここに行き着いたかというと、アニメーションを2つ続けるとうまく動かない(並列動作してしまう)ため、もう少しうまく動かしたかったためです。

で、結果は次のコード。隠してからcompletionで表示すればいいということになります。

今ひとつ文法理解していないけど、こういうことですw


- (void)hideAndShow_hideView:(UIView *)hideView showView:(UIView *)showView{
    // アニメーションでビューを隠す
    self.view.frame = CGRectMake(0, [[UIScreen mainScreen] bounds].size.height-100, [[UIScreen mainScreen] bounds].size.width, 100);
    [UIView animateWithDuration:1.0f
                          delay:0.0f
                        options:UIViewAnimationOptionCurveEaseInOut
                     animations:^{
                         self.view.frame = CGRectMake(0, [[UIScreen mainScreen] bounds].size.height-50, [[UIScreen mainScreen] bounds].size.width, 100);
                     }
                     completion:^(BOOL finished){
                         hideView.hidden = YES;
                         showView.hidden = NO;
                         [UIView animateWithDuration:1.0f
                                               delay:0.0f
                                             options:UIViewAnimationOptionCurveEaseInOut
                                          animations:^{
                                              self.view.frame = CGRectMake(0, [[UIScreen mainScreen] bounds].size.height-100, [[UIScreen mainScreen] bounds].size.width, 100);
                                          }
                                          completion:^(BOOL finished){
                                          }
                          ];
                     }
     ];

}

0 件のコメント:

コメントを投稿