2016-01-22 86 views
0

我有一些(20 - 30)圖像存儲在應用程序中,並將它們加載到集合視圖時,它們從屏幕截圖中所示的小圖像開始滾動,然後滾動它們成爲正常尺寸。在收集視圖中緩慢加載圖像,swift

關於如何解決此問題的任何想法?非常困惑,爲什麼!

這裏是我的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

+0

添加你的代碼在你的問題 –

+0

是否設置圖像的約束是否正確?還需要設置UIImage內容模式爲AspectFit – iOSEnthusiatic

+0

@Rushisangani我已經完成了這兩個。 – Gugulethu

回答

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!