Rasto
Rasto

Reputation: 17844

UIVisualEffectView in cells slows scrolling of UICollectionView

I have UICollectionView that contains cells with large images. Scrolling was smooth until I added (small) UIVisualEffectView to each cell. Now, scrolling performance is awful.

Here is all the code that does something with that UIVisualEffectView the code:

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

What can I do to improve scrolling performance?

Upvotes: 1

Views: 965

Answers (1)

matt
matt

Reputation: 535890

Don't use UIVisualEffectView in this way, that's what you can do. Apple has given lots of info about animation / scrolling performance and that sort of thing is at the top of the list of what not to do. And visual effect views are the worst; they don't merely blur an image - they are performed at a much higher point in the render chain, and you are forcing them to re-render on every frame (hence the problem).

Upvotes: 3

Related Questions