单元格中的 UIVisualEffectView 会减慢 UICollectionView 的滚动速度

UIVisualEffectView in cells slows scrolling of UICollectionView

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)
        }
    }
}

如何提高滚动性能?

不要这样使用UIVisualEffectView,那是你能做的。苹果已经提供了很多关于动画/滚动性能的信息,而这类事情是最不能做的事情。并且视觉效果视图是最差的;它们不仅仅是模糊图像 - 它们是在渲染链中更高的位置执行的,并且您迫使它们在每一帧上重新渲染(因此出现问题)。