2009年11月6日金曜日

マイ・アニメーションブロック

iPhone アプリ開発で、起動時にスプラッシュスクリーンを入れたいときとか、細かいアニメーションをたくさん入れたい時に、自分用のアニメーションブロックみたいなのを作ると、コードが読みやすくなるし、タイプ量も減って、コードがメンテナンスしやすくなる。

  1. - (void)animDur:(float)dur next:(SEL)sel {  
  2.     [UIView beginAnimations:nil context:nil];  
  3.     [UIView setAnimationDuration:dur];  
  4.     [UIView setAnimationDelegate:self];  
  5.     [UIView setAnimationDidStopSelector:sel];  
  6. }  
  7.   
  8. - (void)anim {  
  9.     [UIView commitAnimations];  
  10. }  
  11.   
  12. - (void)sleepDur:(float)dur next:(SEL)next {  
  13.     [NSTimer  
  14.      scheduledTimerWithTimeInterval:dur  
  15.      target:self selector:next userInfo:nil repeats:NO];  
  16. }  
  17.   
  18. - (void)splash0 {  
  19.     [self animDur:0.4 next:@selector(splash1)];  
  20.     splash.alpha = 1;  
  21.     [self anim];  
  22. }  
  23. - (void)splash1 {  
  24.     [self sleepDur:1.5 next:@selector(splash2)];  
  25. }  
  26.   
  27. - (void)splash2 {  
  28.     [self animDur:1.0 next:@selector(splash3)];  
  29.     splash.alpha = 0;  
  30.     [self anim];  
  31. }  
  32.   
  33. - (void)splash3 {  
  34.     [self animDur:1.0 next:nil];  
  35.     mainView.alpha = 1;  
  36.     [self anim];  
  37. }  

0 件のコメント:

コメントを投稿