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

如果这两种方法中的哪一种是合适的,则可以:

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

老兄,我可能会醉酒,但CAlayers没有drawRect方法

我认为你可以使用drawInContext:实际上(吞下)吸引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"); 

说一个人有胆量写自己的drawInContext:

在这种情况下,当您调用displayAsNeeded时,它被调用(或抽象出…或重新计算,或者其他东西)。 (我从来没有需要调用displayAsNeeded:这是肯定的。)