【问题标题】:Exactly what should happen in a CALayer's display/drawRect methods?在 CALayer 的 display/drawRect 方法中究竟应该发生什么?
【发布时间】:2011-01-23 17:22:18
【问题描述】:

如果有的话,这些方法中的哪一个是合适的地方:

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

【问题讨论】:

    标签: iphone macos ios drawing calayer


    【解决方案1】:

    伙计,我可能喝醉了……但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:,这是肯定的。)

    【讨论】:

      猜你喜欢
      • 2017-01-03
      • 2011-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多