Group Group Group Group Group Group Group Group Group

raywenderlich.com Forums

Video Tutorial: CALayers Part 4: Conclusion

Learn how to mask CALayers and then review what you've learned in the CALayers video tutorial series.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/3246-calayers/lessons/5

Great lecturer, very clear.

1 Like

Awesome video series on CALayers. Thank your very much Caroline!

1 Like

Amazing course, everything clear.

1 Like

I like that you have a distinction in this series between code that’s intended to run once, late in one of the multiple initializers: setup, and other code that will run multiple times: configure. Are you still using this convention? Although it’s a common pattern, I haven’t seen consensus on what people call these types of functions.

@jcatterwaul - I like that you pick up on these things. I tend to look at results and code readability primarily and secondly the structure of how we got there. So when you ask a question on why it’s called setup - I would call it that because that’s what it does. I haven’t thought about a convention. But I would like there to be one, so that I can use it consistently.

I think that setup and configure are a good way to go with this. Ray originally did this series, and that naming convention is quite probably what he had in mind. So let’s run with it?

1 Like

Thank you for the great lecture… :slight_smile: …,

1 Like

@caroline After learning all this videos, I have some questions, As we all know, code like below will cause off-screen rendered.

imageView.layer.cornerRadius = CGRectGetHeight(imageView.bounds)/2.0
imageView.layer.masksToBounds = true

so

  1. what is the best practice of circular view or image ? and if there is no best practice, could you give me some strategies and when to use them.
  2. what is off-screen rendered and why using masksToBounds will cause off-screen rendered, could you explain all of these ?

@caroline Can you please help with this when you get a chance? Thank you - much appreciated! :]

  1. Corner radius is great for single images. If you have a table view, and it slows down, then I would recommend drawing the image in a circle using Core Graphics. However, it all depends on exactly what you are doing, and I wouldn’t recommend optimizing until you find that it is necessary. As devices get faster, it becomes less important.
  2. There’s an excellent article explaining off-screen rendering here: https://www.objc.io/issues/3-views/moving-pixels-onto-the-screen/#offscreen-rendering. The primary objective is to get pixels onto the screen as quickly as possible, but when you use transparency or masking, the layer has to be composed off screen.
    For example, render objects A B and C. If all the objects are opaque, that’s a simple operation, and A might be behind B and C. If B has a mask or transparency, then the GPU has to work out which pixels should be partially or completely rendered, so everything gets taken off direct rendering to the screen in case it’s too complex to be rendered quickly, leading to flickering.