从 hitTest 返回自定义 CALayer 子类时出现问题

发布于 2024-10-03 04:16:43 字数 685 浏览 0 评论 0原文

我试图通过命中测试来识别自定义 CALayer 子类。 除了一个例外之外,它工作得很好:

我的自定义 CALayers 代表文本窗口,所有数据(内容、背景颜色、位置……)均取自 NSManagedObjects(来自 CoreData)。我的 CALayer 子类将其相关的 ManagedObject 类保存在实例变量中。 问题是:我无法访问此 ivar:

当我像这样检查时:

CustomCALayer *customLayer =[self.layer.presentationLayer hitTest:mouseDownPosition];   

...customLayer 包含 CALayer 具有的所有属性(例如 backgroundColorname),但不是我的 ManagedObject ivar。 我怀疑发生这种情况是因为 hitTest 返回 CALayer 而不是我的子类。

但我该如何解决这个问题呢?

(我还尝试对我的图层的“hitTestLayer”子图层进行命中测试,然后通过 hitTestLayer.superlayer 获取图层。但是,superlayer 也会返回 CALayer< /代码>...)

I’m trying to identify custom CALayer subclasses via hittesting.
That works fine with one exception:

My custom CALayers represent text windows and all the data (content, background color, position, ...) are taken from a NSManagedObjects (from CoreData). My CALayer subclass saves it’s related managedObject class in an instance variable.
The Problem is: I can't access this ivar:

When I check like so:

CustomCALayer *customLayer =[self.layer.presentationLayer hitTest:mouseDownPosition];   

...the customLayer contains all the attributes, that CALayer has, (like backgroundColor or name) but not my managedObject ivar.
I suspect that this happens because hitTest returns CALayer and not my subclass.

But how can I get around that?

(I also tried to hittest a „hitTestLayer“ sublayer of my layer and then get the layer via hitTestLayer.superlayer. But, well, superlayer also returns CALayer...)

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

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

发布评论

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

评论(1

烟雨凡馨 2024-10-10 04:16:43

您是否重写了自定义 CALayer 的 - hitTest 方法以返回 CustomCALayer 而不是 CALayer?

Did you override the custom CALayer's - hitTest method to return CustomCALayer instead of CALayer?

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