Swift2 iOS- SDWebImage在UICollectionView中闪烁

时间:2016-11-24 18:19:59

标签: ios swift2 uicollectionview sdwebimage

我有一系列图像字符串,我从Firebase中提取。我将这些图像转换为NSURL数组,然后使用sdwebimage将这些URL加载到我的collectionView中。我得到的图像,但我不断闪烁的图像。我在哪里遇到这个问题?

@IBOutlet weak var collectionView: UICollectionView!

//There are a maybe 2 or 3 strings inside here
var imageStrings = [...]()
var imageNSURLs:[NSURL] = []


override func viewDidLoad() {
        super.viewDidLoad()
        for imageString in self.imageStrings{
            let url = NSURL(string: imageString)
            self.imageNSURLs.append(url)
        }

        self.collectionView.reloadData()
    }

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return self.imageNSURLs.count
    }

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = self.collectionView.dequeueReusableCellWithReuseIdentifier("ImageCell", forIndexPath: indexPath) as! ImageCell

        //This is the sdwebimage method I use: sd_setAnimationImagesWithURLs(arrayOfURLs: [AnyObject]!)
        cell.imageView.sd_setAnimationImagesWithURLs(self.imageNSURLs)

        return cell
    }

1 个答案:

答案 0 :(得分:1)

您在sd_setAnimationImagesWithURLs

中使用cellForItemAtIndexPath

如果您不想要,请使用sd_setImageWithURL,并且您需要一次为您的商品传递单个网址,例如

cell.imageView.sd_setImageWithURL(imageNSURLs[indexPath.row])