在Mavericks下将CIFilter添加到CALayer中?

22

这是向层添加过滤器的标准方法:

NSView *view = self.window.contentView;
view.wantsLayer = YES;
CATextLayer *textLayer = [CATextLayer layer];
textLayer.frame = CGRectMake(10.0, 10.0, 200.0, 100.0);
textLayer.string = @"foo";
textLayer.foregroundColor = [[NSColor redColor] CGColor];

// Add filter
CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur" keysAndValues:@"inputRadius", @5.0, nil];
textLayer.filters = @[filter];

// Attach layer
[view.layer addSublayer:textLayer];

然而,在OS X Mavericks上,它会导致我的应用程序崩溃。在10.8上曾经能够正常工作。

2013-10-23 13:09:20.767 Serus[3608:303] *** Terminating app due to uncaught exception 'CAInvalidCIFilter', reason: 'CI filters are not supported by this layer tree: {CIGaussianBlur {
    inputImage = "<null>";
    inputRadius = 10;
}}.'

此图层树不支持CI过滤器

有人见过这个吗?我可能做错了什么?

1个回答

45

明白了,苹果决定无缘无故地更改这个并要求一个新标识

progressIndicator.layerUsesCoreImageFilters = YES;

谢谢!我在使用 setCompositingFilter: 时也遇到了相同的问题,这个解决了它。 - uliwitness
2
这不是没有原因,而是因为默认情况下CALayers现在是在进程之外呈现的,以便让操作系统更好地共享资源。可能可以更好地记录 - 我可以建议一个雷达 :) /cc @uliwitness - Mark
1
从此方法的文档中可以看到,如果您使用setBackgroundFilters:、setCompositingFilter:或setContentFilters:方法将Core Image过滤器分配给视图,则不需要显式调用此方法。这些方法会自动让AppKit知道它需要在进程中呈现层次结构。 - uchuugaka
9
需要翻译的内容:It should be noted that this is a property set on the NSView, not the layer.. And for anyone interested... it is declared in the AppKit.h header.这是一个设置在 NSView 上的属性,而不是在图层上。对于任何感兴趣的人,请注意... 它在 AppKit.h 头文件中声明。 - Alex Gray
我也被这个问题搞崩了! - Chad Cache

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接