究竟应该在CALayer的display/drawRect方法中发生什么?

Wil*_*sch 2 iphone macos drawing calayer ios

这些方法中哪一个(如果有的话)适合:

  • 更改CATextLayer的文本
  • 将不同的图像加载到CAImageLayer中
  • 告诉子层自己更新

Fat*_*tie 6

老兄我可能会喝醉...但是没有drawRect方法 CAlayers

我认为你可以使用drawInContext:实际(gulp)吸引到CALayers,但自二战以来没有人能够做到这一点.

关于显示,您不需要调用它,它基本上更新您使用的设置.contents.

我只是用.contents这样的东西......

[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");
Run Code Online (Sandbox Code Playgroud)

说一个人有勇气写自己的drawInContext:......

在这种情况下,当你打电话时,它会被调用(或抽象出来......或者重新计算,或者其他东西)displayAsNeeded.(我从来不需要打电话displayAsNeeded:,这是肯定的.)