小编Kev*_*fer的帖子

performBatchUpdates上的UICollectionView性能问题

我们正在尝试使用自定义布局设置UICollectionView.每个CollectionViewCell的内容都是一个图像.总之,将会有数千张图像,并且在某个特定时间可以看到大约140-150张图像.在动作事件中,可能会在位置和大小上重新组织所有单元格.目标是使用performBatchUpdates方法为当前所有移动事件设置动画.在一切变得动画之前,这会导致很长的延迟时间.

到目前为止,我们发现内部方法layoutAttributesForItemAtIndexPath是为每个单元格调用的(总共几千个).另外,调用方法cellForItemAtIndexPath以获得比实际可以在屏幕上显示的更多的单元格.

有没有可能提高动画的性能?


默认的UICollectionViewFlowLayout无法真正提供我们想要在应用程序中实现的那种设计.这是我们的一些代码:

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
RPDataModel *dm = [RPDataModel sharedInstance]; //Singleton holding some global information
NSArray *plistArray = dm.plistArray; //Array containing the contents of the cells
NSDictionary *dic = plistArray[[indexPath item]];
RPCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CELL" forIndexPath:indexPath];
cell.label.text = [NSString stringWithFormat:@"%@",dic[@"name"]];
cell.layer.borderColor = nil;
cell.layer.borderWidth = 0.0f;
[cell loadAndSetImageInBackgroundWithLocalFilePath:dic[@"path"]]; //custom method realizing asynchronous loading of the image inside of each cell
return cell;
}
Run Code Online (Sandbox Code Playgroud)

layoutAttributesForElementsInRect遍历所有元素,为rect中的所有元素设置layoutAttributes.for语句在第一个单元格中断,超过了rect右下角定义的边框:

-(NSArray*)layoutAttributesForElementsInRect:(CGRect)rect {
NSMutableArray* attributes = [NSMutableArray array];
RPDataModel *dm = …
Run Code Online (Sandbox Code Playgroud)

performance ios ios6 uicollectionview

7
推荐指数
1
解决办法
5809
查看次数

标签 统计

ios ×1

ios6 ×1

performance ×1

uicollectionview ×1