Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olgusirman/e48c715d135b0396964a09f91ce3ed68 to your computer and use it in GitHub Desktop.
Save olgusirman/e48c715d135b0396964a09f91ce3ed68 to your computer and use it in GitHub Desktop.

What are the render phases?

- Render prepare

- Render execute

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

Find hitches with Instruments?

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".

Recommendations

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment