我有一个UICollectionView,它的项目包含一个imageview,我正在应用CIFilters。因此,大约有12项是生成的,但是当我在集合视图中滚动项时,在生成新项时会出现一些小问题。是否有任何方法在没有此延迟的情况下配置UICollectionView项。
目前,我正在UICollectionView的UICollectionView委托方法中应用过滤器。
// filters array
let arrayOfCIFilters = ["CIBumpDistortionLinear","CIPixellate","CISepiaTone","CITwirlDistortion","CIUnsharpMask","CIVignette","CIPhotoEffectNoir","CIColorInvert","CIMotionBlur","CIColorClamp","CIToneCurve","CIColorPosterize","CICircularScreen"]
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("c1", forIndexPath: indexPath) as! filterImagesCollectionViewCell
let ciImage = CIImage(image:originalImage)
ciFilter = CIFilter(name: arrayOfCIFilters[indexPath.row])!
ciFilter.setValue(ciImage, forKey: kCIInputImageKey)
cell.imageVIew.image = UIImage(CGImage: ciContext.createCGImage(ciFilter.outputImage!, fromRect: ciFilter.outputImage!.extent))
cell.nameLabel.text = arrayOfCIFilters[indexPath.row]
return cell
}发布于 2016-05-11 11:07:02
每次查看单元格时都生成CIImage、CIFilter、UIImage。请记住,每当当前显示单元格时,都会调用cellForItemAtIndexPath,因此当用户滚动并返回时,将再次执行此函数。
您应该在init()方法中创建所有图像,并将它们保存在数组中。然后使用此函数中的图像来显示它们。
https://stackoverflow.com/questions/37160201
复制相似问题