集合视图中的图像加载缓慢,swift
Slow loading of images in a collection view, swift
我在应用程序中存储了一些 (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
}
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!
我在应用程序中存储了一些 (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
}
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!