Skip to content

Instantly share code, notes, and snippets.

@nantekkotai
Created May 31, 2012 03:54
Show Gist options
  • Save nantekkotai/2840844 to your computer and use it in GitHub Desktop.
Save nantekkotai/2840844 to your computer and use it in GitHub Desktop.
UIViewでアニメーションを行う

UIViewを継承したものであればアニメーションを実行することができる。

// 適当な要素が透明になるとする
hoge.alpha = 1.0;

[UIView animateWithDuration:0.2f
                      delay:0.2f
                    options:UIViewAnimationOptionCurveEaseOut
                 animations:^{
                     hoge.alpha = 0.0;
                 }
                 completion:^(BOOL finished){
                     // 透明度0になったら、要素自体を隠す
                     hoge.hidden = YES;
                 }];

説明

  • animateWithDuration
    アニメーションで実行される秒数のこと。
  • delay
    遅延の秒数。
  • options
    アニメーションの性質を変更できる。イーズインやリニアなど。
  • animations アニメーションの最終値を指定する。
    実際の動作では、この値を目指してアニメーションしていく。
  • completion
    完了時に一度実行される。

注意

必ずその秒数が実行されるわけではない。
上の例で言えば、実行前から既にalpha = 0だった場合は、アニメーションは即終了となる。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment