IOS-Smooth Solution for setting the view rounded corner Style
Code
// Set the corner view style-(void) setUpSelfView {// Shadow self. layer. shadowColor = [UIColor blackColor]. CGColor; // black self. layer. shadowOpacity = 0.33; // shadow opacity self. layer. shadowOffset = CGSizeMake (0, 1.5); // The Shadow offset self. layer. shadowRadius = 4.0; // shadowRadius self. layer. shouldRasterize = YES; // rounded corner cache self. layer. rasterizationScale = [UIScreen mainScreen]. scale; // improve smoothness // rounded self. layer. cornerRadius = 10.0f ;}
Instructions:
Context switching
Context switching, whether in the GPU rendering process or the familiar process switching, is a very time-consuming operation. First, I want to save the current screen rendering environment, switch to a new painting environment, apply for drawing resources, initialize the environment, and then start a painting. After the painting is complete, destroy the painting environment, if you need to switch to On-Screen Rendering or start a new operation before repeated off-Screen Rendering. Describes a mask rendering operation.
self.layer.shouldRasterize = YES; self.layer.rasterizationScale = [UIScreen mainScreen].scale;
In most cases, the number of frames saved is more than 55 per second. ShouldRasterize = YES will cache the rendering content of the view, and the cache will be displayed directly next time you draw it. Of course, the view content will not change.
In addition to the dead, it is better to generate a rounded image in advance and cache the image. The pre-processed rounded corner image can be processed in the background, cached after processing, and displayed in the main thread. This avoids unnecessary off-screen rendering.
In addition, there is also a method to cover a hollow circular image on the image to achieve the circular Avatar effect, which is also an extremely efficient method. The disadvantage is that the background of the view is required, and the effect of the monochrome background is the most ideal.
Summary
The implementation of the rounded corner cornerRadius is much more efficient than the mask.
Rasterize greatly reduces GPU work in most cases. In the case of space, the cache can always help you in most cases, isn't it?
Background preprocessing can also be very easy to help you.