繁体   English   中英

CIFilter-无法更改名称

[英]CIFilter - Can't Change Name

从Apple的Core Animation编程指南中 ,清单4:

...
// create the filter and set its default values
CIFilter *filter = [CIFilter filterWithName:@"CIBloom"];
[filter setDefaults];
[filter setValue:[NSNumber numberWithFloat:5.0] forKey:@"inputRadius"];

// name the filter so we can use the keypath to animate the inputIntensity
// attribute of the filter
[filter setName:@"pulseFilter"];
...

在[filter setName ...”行上,我得到一个“'CIFilter'的无可见@interface声明选择器'setName:'

我看到该过滤器是使用filterWithName初始化程序创建的,因此我怀疑其名称是只读的。 但是,为什么在苹果代码以及我发现的许多其他示例中都使用了这个示例?

可写name属性是通过仅在Mac上存在的Core Animation添加类别添加的。 请参阅“ CIFilter动画属性”小节

Core Animation将以下可设置动画的属性添加到Core Image的CIFilter类。 有关更多信息,请参见CIFilter核心动画添加。 这些属性仅在OS X上可用。

  • 名称
  • 已启用

iOS上的CIFilter确实具有-name方法,但这仅用于对过滤器名称的只读访问,并且没有匹配的setter。

上面链接到的《 Core Animation编程指南》中的该部分是从该指南的原始Mac版本复制并粘贴的,应该进行更改,因为它并不完全适用于iOS。

坦白地说,我从未见过尝试更改CIFilter名称的示例-从filterWithName中得到的是一个高度专用的对象。 如果查看类文档,它将显示一个返回名称的方法“ name”,但不包含可读写的属性。

如果需要对象的键路径,则将其存储在类的属性中,然后可以通过setValue:... forKeyPath:@“ myClass.myIvar”访问它。

编辑:只是要完全清楚:

Core Image was added in iOS 5. Also the statement in the answer is not correct. Look in the CIFilter class description "name
The name of the filter.

- (NSString *)name
Return Value
A string that holds the name of the filter.

Availability
Available in iOS 5.0 and later.
Declared In
CIFilter.h

在CIFilter.h中查看iOS5.1:

 "- (NSString*)name __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_5_0);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM