2

I have been struggling with this issue for weeks now. Anyway, CALayer's are awful. They cause so much lag and make my UI look even worse.

Pretty much I have a simple UITableView that I have maxed out in efficiency and all of the lag when scrolling comes from 3 lines of code:

CALayer *imageLayer2 = [cell.imageView layer];
[imageLayer2 setMasksToBounds:YES];
[imageLayer2 setCornerRadius:10.0];

I have tried to set the setMaskToBounds to NO, but then no rounded corners are applied to my UIImageView. It seems that this issue is worse on iPads then on iPhones for some odd reason but ill just stick to finding a workaround for now. Also this code is in my cellForRowAtIndexPath but only is executed if a new cell is needed so it is not always called.

Anyway, what do you recommend I do instead of using CALayers to get rid of this lag?

Thanks!

SimplyKiwi
  • 12,376
  • 22
  • 105
  • 191

3 Answers3

1

I think the problem here is because you are doing this every time the cellForRowAtIndex is called. What I would advise, is store the image already with the mask and the corner radius, when you actually need then again, you ask the model to retrieve the image and not calculate it again. The cellForRowAtIndex, is a sensible spot, and you should avoid doing expensive operations in it.

Rui Peres
  • 25,741
  • 9
  • 87
  • 137
1

I have found if you use a CGImageRef of your UIImage, it is much faster than using the UIImage directly.

Try this:

CALayer *imageLayer2.contents = (id)[cell.imageView image].CGImage;
[imageLayer2 setMasksToBounds:YES];
[imageLayer2 setCornerRadius:10.0];

Although I would actually get rid of the ImageView completely and just deal with CALayers and UIImages (Assuming you don't care about accessibility)

Robert Wagstaff
  • 2,664
  • 1
  • 27
  • 40
0

Well if you are willing to messing with the image itself, you could make it round rect and then use it as it is, For updating a rectangular image to a round rect one, check this answer How to mask a square image into an image with round corners in the iPhone SDK?

Community
  • 1
  • 1
Omar Abdelhafith
  • 21,163
  • 5
  • 52
  • 56