We would like to draw a shadow, depends on the z-dimension hierarchy, first It needs to render to elements before the shadow rendering. That means, It needs to wait fake elements for drawing the render, after that the elements draw itself. This is called Offscreen pass second 4.14 An offscreen pass is anytime the GPU must render a layer bh first rendering it somewhere else and then copying it over. With the shadow, it had to draw the layers to figure out the final shape. You need to avoid the render hitches.
4 offscreen pass;
- Shadowing
- Masking
- Rounded rectangles
- Visual effects
Animation Hithces in Instruments. Hitches track most important one. This is the amount of time since the frame should have been ready. Renders and GPU tracks show the work performed by the render server. You can see the layers on Xcode 3d debugger now. New runtime issue type "Optimization Opportunities".
Always use provided API's.
- shadowPath
- cornerRadius, cornerCurve
Avoid using masks or corner contents to form rounded rectangle shapes
All you need for shadow;
// setup shadow properties
view.layer.shadowColor = UIColor.black.cgColor
view.layer.shadowOpacity = 0.5
// set a shadow path on a basic layer
view.layer.shadowPath = UIBezierPath(roundedRect: view.layer.bounds, cornerRadius: view.layer.cornerRadius).cgPath
- Use
maskToBounds
where possible instead of setting a custom mask. - Avoid enabling
maskToBounds
if content will not exceed bounds.