7

I'm currently working on a rewrite of a tweak (runs inside SpringBoard itself) and so (of cause) smoothness, speed and efficiency are some of the most important things for me as even the slightest bit of unnecessary lag will take away from the UX.

So my question is how can I round the views corners with the minimal amount of lag.

The obvious one is:

view.layer.cornerRadius = value;
view.layer.masksToBounds = YES;

However I've heard that setting a CALayer mask with layer.mask is faster? And if so which of these 2 solutions is best?: https://stackoverflow.com/a/4930166/458205

This code uses masking however the mask layer is using cornerRadius as well so is this actually any faster?

CALayer *maskLayer = [CALayer layer];
maskLayer.cornerRadius = radius;
// set the mask
self.view.layer.mask = maskLayer;

Or would Solution 1, of the above link, or this answer be more effecient?

I know I'm referencing another question several times, however that question is about masking only 2 corners (which throws up a few different solutions) however I'm asking for the most efficient way to have 0.6 screen size views scroll as smoothly as possible with rounded corners (like this image). CardSwitcher Screenshot

Community
  • 1
  • 1
Kyle Howells
  • 3,008
  • 1
  • 25
  • 35

2 Answers2

3

You need to set the rasterizationScale as well as view.layer.shouldRasterize.

I typically do this:

view.layer.shouldRasterize = YES;
view.layer.rasterizationScale = [[UIScreen mainScreen] scale];

If you don't set the rasterizationScale it will always default to a scale of 1 (non-retina in this case) for rasterization.

For me this usually puts my scroll performance on par with the UITableView's.

James Jones
  • 1,486
  • 1
  • 12
  • 22
1

The first snippet is more efficient because the rounded corner is a mask by itself. to increase performance of rounded corners use: view.layer.shoudRasterize = YES;