-5

水平のテーブル ビューがあり、5 秒ごとに画像を変更したいと考えています。古い画像がフェードアウトし、新しい画像がフェードインするように、フェードアニメーションで画像を変更したいので、このメソッドを呼び出します:

self.slideTimer = [NSTimer scheduledTimerWithTimeInterval:5
                                                   target:self
                                                 selector:@selector(slideToNextImage)
                                                 userInfo:nil
                                                  repeats:YES]; 

そして、これが私のものですslideToNextImage:

 self.lastIndexPath = indexPath;
 [UIView beginAnimations:@"FadeAnimations" context:nil];
 [UIView setAnimationDuration:2];
 self.horizontalView.alpha = 0.1f;
 [self.horizontalView.tableView scrollToRowAtIndexPath:self.lastIndexPath
         atScrollPosition:UITableViewScrollPositionMiddle
              animated:NO];
 [UIView commitAnimations];
 [UIView beginAnimations:@"FadeAnimations" context:nil];    
 [UIView setAnimationDuration:2];
 self.horizontalView.alpha = 1.0f;
 [UIView commitAnimations];

私の認識では、画像のフェードが速すぎて、2番目の画像がフェードアニメーションなしでスクロールしているのがわかります

4

1 に答える 1

3

最初のアニメーションが終了するのを待たずに、2 番目のアニメーションが開始されます。

代わりに次のようにしてみてください。

[UIView animateWithDuration:2.0 animations:^{
    self.horizontalView.alpha = 0.1f;
    [self.horizontalView.tableView scrollToRowAtIndexPath:self.lastIndexPath
                                         atScrollPosition:UITableViewScrollPositionMiddle
                                                 animated:NO];

} completion:^(BOOL finished) {
    [UIView animateWithDuration:2 animations:^{
        self.horizontalView.alpha = 1.0f;
    }];
}];
于 2012-08-22T16:10:19.773 に答える