【问题标题】:Fade animation when scrolling horizontal table view滚动水平表视图时淡入淡出动画
【发布时间】:2012-08-22 15:27:33
【问题描述】:

我有一个水平表格视图,想每 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];

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

【问题讨论】:

  • 你能提供更多关于你想做什么和问题是什么的信息吗?!
  • 请做一些截图来说明你的要求。
  • 抱歉,编辑了我的帖子,希望对您有所帮助
  • 我看不到任何截图。 :(

标签: iphone ios xcode uitableview uiviewanimation


【解决方案1】:

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

试试这样的方法:

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

【讨论】:

  • 谢谢,这行得通,但动画不流畅我看到执行 scrollToRowAtIndexPath: 时有些滞后。有没有可能让它顺利?
  • 这段代码可能不是导致动画断断续续的问题。你还在做什么来消耗处理能力/消耗大量内存?
  • 所以滚动不应该是动画的?您可以在第二个动画之前在完成块内移动 scrollToRow 方法调用!
  • 是的,我这样做了,而且效果很好,但是动画不流畅。执行 scrollToRowAtIndexPath: 时,我看到一些闪烁。我在其他应用程序中看到了相同的功能,这些应用程序运行起来非常流畅。也许我使用了错误的方法?滚动表格视图不是解决方案?
猜你喜欢
  • 2019-01-01
  • 2021-10-07
  • 2011-09-19
  • 2020-12-30
  • 2014-01-20
  • 2012-12-18
  • 2016-02-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多