2

When scrolling down in my UICollectionView it lags, and caused by this:

imageCell?.backgroundColor = UIColor.whiteColor()
imageCell?.layer.masksToBounds = false
imageCell?.layer.shadowOpacity = 0.5
imageCell?.layer.shadowRadius = 5.0
imageCell?.layer.shadowOffset = CGSizeZero
imageCell?.layer.shadowColor = UIColor.grayColor().CGColor

imageCell is the cell name:

let imageCell = collectionView.dequeueReusableCellWithReuseIdentifier("imageCell", forIndexPath: indexPath) as? CollectionViewCell

Any suggestions what i should do?

Roduck Nickes
  • 1,021
  • 2
  • 15
  • 41

2 Answers2

1

When using shadows, it is a good idea to specify the shadowPath if you know the shape.

imageCell?.layer.shadowPath = UIBezierPath(rect: imageCell?.frame ?? CGRectZero).CGPath

Apple mentions

Specifying an explicit path usually improves rendering performance.

Caleb
  • 5,548
  • 3
  • 25
  • 32
0

I ran into this same thing when I was using images that were too big. I converted then to .png and made them smaller - that helped. (not sure if you are using any images).

But the thing that really made a difference was rasterizing

cell.layer.shouldRasterize

Community
  • 1
  • 1
Jay
  • 34,438
  • 18
  • 52
  • 81