Adding CIFilter to CALayer under Mavericks?

2019-01-23 03:13发布

问题:

so this is the standard way of adding filter to a layer:

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];

However, it crashes my application on OS X Mavericks. Used to work on 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 filters are not supported by this layer tree

Anybody ever seen this? What may I be doing wrong?

回答1:

Figured it out, Apple decided to change this and require a new flag for no reason

progressIndicator.layerUsesCoreImageFilters = YES;