CALayer和CAAnimation对未实现的属性访问器的动态解析 [英] CALayer and CAAnimation's dynamic resolution of unimplemented property accessors

查看:64
本文介绍了CALayer和CAAnimation对未实现的属性访问器的动态解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现CALayer和CAAnimation不仅扩展了关键值编码的核心动画扩展,而且还为未实现的属性访问器提供了动态分辨率。例如:

I found that CALayer and CAAnimation don't only extend the NSKeyValueCoding protocol as described in Core Animation Extensions To Key-Value Coding, but also offer dynamic resolution for unimplemented property accessors. For example:

@interface DotLayer : CALayer
@property (nonatomic, retain) id dot;
@end

@implementation DotLayer
@dynamic dot;
@end

仅带有属性声明并声明它为 @dynamic ,我可以在不实现其访问器的情况下访问 dot 属性:

Simply with a property declaration and stating it is @dynamic, I can access dot property without implementing its accessors:

DotLayer *layer = [DotLayer layer];
NSLog(@"layer responds to dot: %d", [layer respondsToSelector:@selector(dot)]);
layer.dot = nil;
NSLog(@"%@", [layer dot]);

经过进一步调查,我发现这种动态解析是由CALayer和CAAnimation的特殊实现完成的+ resolveInstanceMethod:

After further investigation, I found this dynamic resolution is done by CALayer and CAAnimation's special implementation of +resolveInstanceMethod:.

我在WWDC 2010的ImageBrowser示例代码中看到了此动态分辨率的用法,但找不到任何说明此功能的文档。所以我想知道:

这种动态分辨率是否是我可以在自己的代码中使用的规定行为?

I saw usage of this dynamic resolution in ImageBrowser sample code of WWDC 2010, but I can not find any documentation stating this feature. So I'm wondering:
Is this dynamic resolution a prescribed behavior that I can make use of in my own code?

推荐答案

经过进一步思考,我有一个自己的猜测:
为了扩展NSKeyValueCoding协议,CALayer和CAAnimation为所有未实现的属性访问器在其 + resolveInstanceMethod:。副作用是,没有访问器的@dynamic属性也被覆盖。

After further thought, I have my own guess: To extend the NSKeyValueCoding protocol, CALayer and CAAnimation offer dynamic resolution for all unimplemented property accessors in their implementation of +resolveInstanceMethod:. As a side effect, @dynamic properties without accessors are also covered.

我不确定WWDC示例代码是有意还是无意地编写的。但是,如果我的猜测是正确的,那完全取决于实现,因此我认为我们不应该将其用作功能。

I'm not sure whether the WWDC sample code is written this way intentionally or accidentally. But if my guess is correct, it is quite implementation dependent so I think we should not utilize it as a feature.

这篇关于CALayer和CAAnimation对未实现的属性访问器的动态解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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