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).
If you start with a regular UIView it has square corners. You can give it round corners by changing the cornerRadius property of the view's layer . and smaller values give less rounded corners. Both clipsToBounds and masksToBounds are equivalent.
You can set the cornerRadius property of any UIView to have its edges rounded, but by default that rounds all corners at the same time.
Select the view that you want to round and open its Identity Inspector. In the User Defined Runtime Attributes section, add the following two entries: Key Path: layer. cornerRadius , Type: Number, Value: (whatever radius you want)
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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With