不在层托管视图上调用CALayer委托方法 [英] CALayer delegate methods not called on layer hosted view

查看:51
本文介绍了不在层托管视图上调用CALayer委托方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我拥有该层的托管视图,其初始化方式如下:

I have this layer hosted view, which is initialised like so:

// Init layers
self.wantsLayer = YES;
_hostedLayer = [CALayer layer];
_hostedLayer.delegate = self;
self.layer = _hostedLayer;

很奇怪,未调用委托方法 updateLayer .
当我注释掉最后三行时,它确实会被调用.

Weirdly, the delegate method updateLayer is not called.
When I comment out the last 3 lines, it does get called.

这是怎么了?

提示:是,我已经覆盖了 wantsUpdateLayer 并返回了 YES .

Hint: Yes I have overridden wantsUpdateLayer and return YES.

推荐答案

默认情况下,视图请求图层时,它将获得CALayer的特殊私有子类,该子类具有附加功能.尽管自10.7以来我还没有做过这件事,但是那时候那是一个全有或全无的主张–您要么使用视图获得的默认(私有)层,然后使用AppKit约定进行绘制,要么您创建了自己的CALayer绘图全部由CALayer本身或委托方法处理:

When a view asks for a layer it gets a special, private subclass of CALayer by default, which has extra capabilities. Although I haven’t done this since 10.7, in those days it was an all-or-nothing proposition—you either used the default (private) layer the view got, and got to draw using AppKit conventions, OR you made your own CALayer and drawing was all handled by the CALayer itself or by the delegate methods:

- (void)displayLayer:(CALayer *)layer;
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx;

所以,在您的情况下,我猜这两种方法将在您的视图上调用,而不是特定于视图的-updateLayer.

So, I’d guess in your case these latter two methods would be called on your view, but not the view-specific -updateLayer.

这篇关于不在层托管视图上调用CALayer委托方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆