フェードイン/アウト、上下運動のアニメーション
以前、タイマーを使ってアニメーションさせる方法を書きましたが、フェード以外は動きがなぜかカクカクになるという事態が発生したため別の方法を取ることにしました。以下がフェードイン/アウトです。
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. //アルファチャンネルを設定 p2Twc1Lab.alpha = 0.0; p2Twc2Lab.alpha = 0.0; p2Twc3Lab.alpha = 0.0; //アプリが起動したらアニメーション開始 [self labelAnime]; } ... - (void)labelAnime { //フェードイン、UIViewAnimationOptionRepeatはリピートする・UIViewAnimationOptionAllowUserInteractionはアニメーション中ユーザからの操作を受け付ける設定 [UIView animateWithDuration:3.0 delay: 0 options: UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction animations:^{ p2Twc1Lab.alpha = 1.0; p2Twc2Lab.alpha = 1.0; p2Twc3Lab.alpha = 1.0; } completion:^(BOOL finished){ //フェードアウト [UIView animateWithDuration:5.0 delay: 10.0 options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction animations:^{ p2Twc1Lab.alpha = 0; p2Twc2Lab.alpha = 0; p2Twc3Lab.alpha = 0; } completion:nil]; }]; //上下運動の繰り返し(同じことをタイマーでやろうとするとカクカクになった・・・) [UIView animateWithDuration:13.0 delay:3.0 options:UIViewAnimationOptionRepeat animations:^(void){ ChouV.transform =CGAffineTransformMakeTranslation(0, 14); InkV.transform =CGAffineTransformMakeTranslation(0, 16); } completion:^(BOOL finished){ ChouV.transform =CGAffineTransformMakeTranslation(0, -14); InkV.transform =CGAffineTransformMakeTranslation(0, -16); }]; }