【问题标题】:Cross-Dissolve UIImage in UITableViewCell or UICollectionViewCell在 UITableViewCell 或 UICollectionViewCell 中交叉溶解 UIImage
【发布时间】:2014-02-25 13:02:58
【问题描述】:

我有一个 UICollectionView,其中包含包含 ImageViews 的单元格。下载我想在单元格中显示的图像后,我想将我的图像与单元格内已经存在的占位符图像交叉融合。

一切都按预期工作,但是当我开始重用 CollectionViews 时,我开始看到奇怪的东西。

  • 我的占位符图像的设置(在没有动画的情况下完成)被忽略了。
  • 在我重新加载集合/表格视图后,它会淡出的图像是最后一个可见的图像(在其他单元格中)。

我目前正在使用以下代码:

weakSelf.image = placeholderImage;
[UIView transitionWithView:weakSelf
                  duration:5.0f
                   options:UIViewAnimationOptionTransitionCrossDissolve
                animations:^{
                     weakSelf.image = image;
              } completion:nil];

但如果我那样做也没关系...

weakSelf.image = placeholderImage;
CATransition  *transition = [CATransition animation];
[transition setType:kCATransitionFade];
transition.duration = 5.0;
[weakSelf.layer addAnimation:transition
                      forKey:@"fade"];
weakSelf.image = image;

是不是 UIViews 的presentationLayer 的缓存问题? 有什么办法可以让我在 UICollectionViews 或 UITableViews 中淡入淡出吗?

编辑:

我上传了一个演示问题的小示例项目... https://dl.dropboxusercontent.com/u/809469/ImageTransition.zip

如果您运行 Demo-App 并点击右上角的重新加载按钮,您会看到图像正在从其他随机图像中褪色。我认为淡入淡出会再次出现在同一张图像之间......而且self.imageView.image = nil;也被某种方式忽略了?!?!

【问题讨论】:

  • 几乎可以肯定,问题出在您的 cellForRowAtIndexPath: 方法中(或者如果您是子类化,则在您的 prepareForReuse 方法中。)。请发布您的代码的这些部分。
  • 我在 prepareForReuse: 方法中什么也没做。它甚至没有实现......但即使我将图像设置为那里的占位符图像,它也不在乎。

标签: ios core-animation calayer uiviewanimationtransition catransition


【解决方案1】:

您可以像这样使用[UIView animateWithDuration:] 并避免所有复杂性:

weakSelf.image = placeholderImage;
[UIView animateWithDuration:5.0f animations:^{
    weakSelf.alpha=0.0f;

} completion:^(BOOL finished) {
    weakSelf.image = image;
    [UIView animateWithDuration:5.0f animations:^{
        weakSelf.alpha=1.0f;

    }];
}];

别忘了在prepareForReuse:中设置weakSelf.alpha=1.0f;weakSelf.image = placeholderImage;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-23
    • 1970-01-01
    • 1970-01-01
    • 2013-11-11
    • 2013-05-18
    • 1970-01-01
    • 2020-02-21
    • 1970-01-01
    相关资源
    最近更新 更多