UIcollectionView 的图像和滚动加载速度缓慢 [英] UIcollectionView has slow jerky loading of images and scrolling

查看:98
本文介绍了UIcollectionView 的图像和滚动加载速度缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UICollectionView,里面有一些图片.在第一次向下滚动时加载图像非常缓慢和生涩.之后,加载图像时就可以了.

I have a UICollectionView with some images in it. It is very slow and jerky to load the images on the first scroll down. After that, when the images are loaded it is fine.

我想问题是图像直到单元格到达屏幕才会加载,这会导致延迟.我假设我需要做的是在图像出现在屏幕上之前加载它们.我不知道该怎么做,显然我在寻找错误的东西,因为我找不到任何答案.请有人能指出我正确的方向吗??

I guess the problem is that the images don't get loaded until the cell reaches the screen which causes a lag. I'm assuming what I need to do is load the images before they appear on the screen. I'm not sure how to do this and am obviously searching for the wrong thing as I can't find any answers. Please can someone point me in the right direction please??

这是加载图像的代码......图像在我的应用程序中没有下载或任何东西.

Here is the code which loads the images...The images are in my app not downloaded or anything.

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"Cell";
    CustomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
    [[cell myImage]setImage:[UIImage imageNamed:[arrayOfImages objectAtIndex:indexPath.item]]];

    return cell;
}

谢谢!

推荐答案

看这个 answer

在出队后添加这两行

cell.layer.shouldRasterize = YES;
cell.layer.rasterizationScale = [UIScreen mainScreen].scale;

这篇关于UIcollectionView 的图像和滚动加载速度缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆