-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];

当我意识到图像褪色太快时,我看到第二张图像滚动时没有褪色动画

4

1 回答 1

3

第二个动画开始而不等待第一个动画结束。

尝试这样的事情:

[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 回答