What exactly should happen in the CALayer display / drawRect methods?

What if any of these methods is a good place to:

  • Change the text of the CATextLayer
  • Load another image in CAImageLayer
  • Let the sublayers update themselves
+2
source share
1 answer

Dude, I can be drunk ... but there is no drawRect method in CAlayers

I think you can use drawInContext:for actual (gulp) drawing in CALayers, but no one is human enough to do this since WW2.

As for the display, you don't need to call it, it basically updates what you installed using .contents.

I just use .contentssomething like this ...

[self.view setLayer:rearLayer];
[self.view setWantsLayer:YES];
rearLayer.frame = CGRectMake(gameBlah,gameBlah, 1024,768);
// note that we are dealing there with the mysteries of rearLayer positioning;
// it is measured by the SUPER layer of the layer in question!
// (indeed much as frame for the view is, if you think about it ..)
rearLayer.contents = (id)loadMacStylePng(@"spaceShip");

, drawInContext:...

( ... , - ), displayAsNeeded. ( displayAsNeeded:, .)

+6

Source: https://habr.com/ru/post/1796554/


All Articles