在集合视图中缓慢加载图像,很快

时间:2016-01-22 11:15:01

标签: ios swift collectionview

我有一些(20 - 30)个图像存储在应用程序中并将它们加载到集合视图中,它们从屏幕截图中显示的小开始,在滚动时它们变为正常大小。

有关如何解决此问题的任何想法?很困惑为什么!

这是我的cellForItemAtIndexPath代码:

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

        let cellSelected = iconCollectionView.dequeueReusableCellWithReuseIdentifier("IconCell", forIndexPath: indexPath) as! IconCollectionViewCell

        cellSelected.workoutImage.image = iconsArray[indexPath.item].exerciseIcon

        cellSelected.layer.shouldRasterize = true
        cellSelected.layer.rasterizationScale = UIScreen.mainScreen().scale;

        return cellSelected
    }

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:1)

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {



    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as? CollectionViewCell
    cell?.imageth.image = UIImage(named: (arrayName[indexPath.row] as? String)!)
    return cell!