アルファベット順のセクションに分割されたテーブル ビューがあります。各セクションのフッターにある UIImage ビューにアニメーション バナーを表示しています。UIImage ビューがクリックされたときにどの画像が表示されるかを判断する必要があります。startAnimating を呼び出す直前にタイマーを設定します。タイマーは、アニメーションの変化と同じ速度で 5 秒ごとに起動しますが、タイマーの起動ははるかに高速です。その5秒間に2、3回発射することもあります。タイマーとアニメーションを開始するコードは次のとおりです。
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger) section {
...
imgAdBar = [[bannerView alloc]initWithFrame:CGRectMake(footer.frame.origin.x,footer.frame.origin.y,footer.frame.size.width,footer.frame.size.height)];
imgAdBar.image=[UIImage imageNamed:[NSString stringWithFormat:@"%@", [animationArray objectAtIndex:0]]];
[imgAdBar saveBannerArray:animationArray];
[imgAdBar setUserInteractionEnabled:YES];
imgAdBar.animationImages = images;
imgAdBar.animationDuration=[images count]*5;
imgAdBar.animationRepeatCount=0;
timerCount=0;
[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(timerRunning:) userInfo:nil repeats:YES];
[imgAdBar startAnimating];
[footer addSubview:imgAdBar];
footer.backgroundColor = [UIColor clearColor];
}
return footer;
}
そして、ここにセレクタがあります:
-(void)timerRunning:(NSTimer*)theTimer
{
NSLog(@"timerCount=%d",timerCount);
imgAdBar.timerCount=timerCount;
if (timerCount==numAnimationImages) {
timerCount=0;
}
NSLog(@"currentImage=%@",[animationArray objectAtIndex:timerCount]);
timerCount++;
}
そのタイマーを使用して画像配列にインデックスを付け、どれが表示されているかを確認できるようにする予定です。発火すべきときに発火しない理由を知っている人はいますか? ご協力ありがとうございます。