【问题标题】:CIFilter - Can't Change NameCIFilter - 无法更改名称
【发布时间】:2012-08-09 02:00:36
【问题描述】:

来自 Apple 的 Core Animation Programming Guide,清单 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 初始化程序创建的,所以我怀疑它的名称是只读的。但是为什么这个例子出现在 Apple 的代码中,以及我发现的许多其他例子中呢?

【问题讨论】:

    标签: objective-c ios cocoa core-animation core-image


    【解决方案1】:

    可写的name 属性是通过Core Animation additions 类别添加的,该类别仅存在于Mac 上。见CIFilter Animatable Properties subsection

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

    • 姓名
    • 启用

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

    您在上面链接到的核心动画编程指南部分是从该指南的原始 Mac 版本复制和粘贴的,应该进行更改,因为它并不完全适用于 iOS。

    【讨论】:

    • 感谢您的回答。我会归档一个雷达。很高兴知道我没疯(至少这次是:)
    • @MichaelMangold - 是的,多年来,复制和粘贴的文档引起了很多混乱,尤其是当 Core Image 甚至不适用于 iOS 时。
    • 顺便说一句,我正在观看您的 Core Animation 视频,您提到 Core Image 在 iOS 上不可用。
    • @DavidH - 我认为你的意思是核心图像,而不是核心动画。自 Leopard 和最初的 iPhone OS 以来,Core Animation 就一直存在。我已经澄清了上面的答案,表明我的意思是一个可设置的属性,它仍然只存在于 Mac 上。在 iOS 上有一个 -name getter,但在 Mac 的 Core Image 上没有匹配的 -setName:
    • @BradLarson 是的,我的错字!最初的发帖人从未看过 iOS 的 CIFilter 文档——这一切都清楚。我从来没有去过 Mac 文档(尽管我之前确实在那里使用过 CIFilter。
    【解决方案2】:

    坦率地说,我从未见过尝试更改 CIFilter 名称的示例 - 您从 filterWithName 得到的是一个高度专业化的对象。如果您查看类文档,它会显示一个返回名称的方法“名称”,但没有可读写的属性。

    如果您需要对象的键路径,则将其存储在类的属性中,然后您可以通过 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);
    

    "

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-22
      • 2011-10-07
      • 1970-01-01
      • 2022-08-23
      • 2023-03-17
      • 1970-01-01
      • 1970-01-01
      • 2018-02-01
      相关资源
      最近更新 更多