Exactly what should happen in a CALayer's display/drawRect methods?

纵然是瞬间 提交于 2020-01-24 16:03:43

问题


Which, if either, of these methods would be an appropriate place to:

  • Change the text of a CATextLayer
  • Load a different image into a CAImageLayer
  • Tell sublayers to update themselves

回答1:


Dude I may be way drunk ... but there is NO drawRect method in CAlayers

I think you can use drawInContext: to actually (gulp) draw in to CALayers, but nobody is man enough to do that since WW2.

Regarding display, you don't need to call it, it basically updates what you set using .contents.

I just use .contents something 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");

Say one had the guts to write one's own drawInContext: ...

In that case, it gets called (or abstracted out ... or recalculated, or something) when you call displayAsNeeded. (I've never needed to call displayAsNeeded:, that's for sure.)



来源:https://stackoverflow.com/questions/4775179/exactly-what-should-happen-in-a-calayers-display-drawrect-methods

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!