首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UICollectionView中的性能问题

UICollectionView中的性能问题
EN

Stack Overflow用户
提问于 2016-05-11 10:40:20
回答 1查看 285关注 0票数 3

我有一个UICollectionView,它的项目包含一个imageview,我正在应用CIFilters。因此,大约有12项是生成的,但是当我在集合视图中滚动项时,在生成新项时会出现一些小问题。是否有任何方法在没有此延迟的情况下配置UICollectionView项。

目前,我正在UICollectionViewUICollectionView委托方法中应用过滤器。

代码语言:javascript
复制
// 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                 
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-11 11:07:02

每次查看单元格时都生成CIImage、CIFilter、UIImage。请记住,每当当前显示单元格时,都会调用cellForItemAtIndexPath,因此当用户滚动并返回时,将再次执行此函数。

您应该在init()方法中创建所有图像,并将它们保存在数组中。然后使用此函数中的图像来显示它们。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37160201

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档