CALayer 的 display/drawRect 方法中到底应该发生什么?

发布于 2024-10-14 07:10:47 字数 123 浏览 1 评论 0原文

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里南柯 2024-10-21 07:10:47

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

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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文