1

我有UICollectionView包含带有大图像的单元格。滚动很顺利,直到我UIVisualEffectView向每个单元格添加(小)。现在,滚动性能很糟糕。

以下是与该代码相关的所有UIVisualEffectView代码:

class ThemeCardCell: UICollectionViewCell {
    private let priceTagEffectView = UIVisualEffectView()

    override func layoutSubviews() {
        super.layoutSubviews()
        if priceTagEffectView.superview == nil {
            priceTagEffectView.effect = UIBlurEffect(style: UIBlurEffectStyle.Light)
            priceTagEffectView.frame = CGRect(x: bounds.width - priceTagMargin.width - 80, y: priceTagMargin.height, width: 80, height: 40)
            priceTagEffectView.opaque = true
            addSubview(priceTagEffectView)
        }
    }
}

我可以做些什么来提高滚动性能?

4

1 回答 1

3

不要以这种方式使用 UIVisualEffectView ,这是你可以做的。Apple 提供了很多关于动画/滚动性能的信息,而这类事情在不该做的事情列表的顶部。并且视觉效果视图最差;它们不仅仅是模糊图像 - 它们在渲染链中的更高点执行,并且您强制它们在每一帧上重新渲染(因此出现问题)。

于 2015-12-03T01:49:35.023 回答