UICollectionView reloadData Cell 图片闪烁一下

2016-10-15 20:54:03 +08:00
 niselover
collectionCell 里包含个 imageView
刷新时 cell 闪烁一下 咋回事。。
performBatchUpdates:completion:也闪
reloadIndexPath:也闪
reloadSections:也闪
好急。。
11281 次点击
所在节点    iDev
21 条回复
kitalphaj
2016-10-15 20:56:28 +08:00
刷新当然会闪。。
niselover
2016-10-15 21:04:49 +08:00
@kitalphaj tableView 就不闪诶。。
tuimaochang
2016-10-15 21:04:58 +08:00
这……
paradoxs
2016-10-15 21:10:09 +08:00
要给 Placeholder 不然肯定会闪的, 要么你就用 sdwebimage
cielpy
2016-10-15 22:13:48 +08:00
你是 reload 了特定的 indexPath 吗
heqichang
2016-10-15 22:20:19 +08:00
同求解答:之前也遇到过一样的问题,用的 sdwebimage ,设了 placeholder , reload 后有时会闪有时不会。
DingSoung
2016-10-15 23:38:37 +08:00
prepare for reused 函数不要清图片,如果取图片需要很长时间 用个默认图顶着,如果图片设置后会触发自动布局也会引起
tutuge
2016-10-16 13:05:59 +08:00
就是因为设置了 placeholder 才会闪
niselover
2016-10-16 16:04:19 +08:00
@paradoxs 用了 sdwebimage 还是闪、、
niselover
2016-10-16 16:04:36 +08:00
@cielpy 不啊 reload 全部哇
niselover
2016-10-16 16:05:45 +08:00
@dingsoung 请教一下 prepare for reused 是啥方法
niselover
2016-10-16 16:06:18 +08:00
@tutuge 没设 placeholder 有时候闪有时候不闪 咋回事
paradoxs
2016-10-16 16:06:47 +08:00
@niselover 丢上来看看
niselover
2016-10-16 16:18:58 +08:00
@paradoxs

Photo *photo = self.allPhotos[indexPath.item];

OneAlbumCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];

cell.imageView.image = nil;

cell.isEditing = collectionView.allowsMultipleSelection;

[cell.imageView sd_setImageWithURL:[NSURL URLWithString:photo.thumImageUrl]];
yongSir
2016-10-16 16:52:11 +08:00
不想让他闪
可以指定 reload 的 index ,也就是不管不刷新
同时在想办法关闭动画,这种老问题 so 上有很多答案
比如,给个参考:
```swift
CATransaction.begin()
CATransaction.setDisableActions(true)
// update or reload here

CATransaction.commit()
```
yongSir
2016-10-16 16:53:09 +08:00
不全部刷新 打错了
niselover
2016-10-16 16:56:59 +08:00
@yongSir 感谢回复 试过了 不顶事 有时候还是闪。。
DingSoung
2016-10-16 17:21:49 +08:00
@niselover - (void)prepareForReuse {} 把 cell API 好好看看吧
ashoka
2016-10-17 08:00:58 +08:00
cell.imageView.image=nil 去掉试下
kobe1941
2016-10-17 08:02:47 +08:00
```
// 去掉 reloadData 时的动画
[UIView performWithoutAnimation:^{
[weakSelf.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
}];
```
之前写关于 UICollectionView 的 demo 的时候确实有遇到这种情况,我是这么解决的:
[点这里]( https://github.com/kobe1941/HFRefresh/blob/master/HFRefresh/HFCollectionViewController.m)

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/313038

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX