简体   繁体   中英

How to animate a CIFilter with CoreAnimation in iOS?

I want to add a filter to a Layer using CABasicAnimation . I'd like to animate some properties of this filter. I read from documentation that the filters property is animatable, but in the same documentation, it seems to be really hard to find a way to do that!

So, how can I refer to a single filter property from a CABasicAnimation with animationWithKeyPath ?

[CABasicAnimation animationWithKeyPath:@"filters._FILTER_._PROPERTY_"];

This is a full example just to show you how I'm trying to get it working:

//Define the filter
CIFilter *filterOne = [CIFilter filterWithName:@"CISepiaTone"];
[filterOne setDefaults];

//Attach it to the Layer
self.layer.filters = [NSArray arrayWithObject:filterOne];

//HERE THE PROBLEM ---------------------------------------
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"filters.???????.inputIntensity"];
//EOF HERE THE PROBLEM -----------------------------------

//Define the Animation settings
animation.delegate = self;
animation.fromValue = [NSNumber numberWithInt:0];
animation.toValue = [NSNumber numberWithInt:1];
animation.duration = 0.3;
...etcetc...

I don't think the layer filters property works at all in iOS. There was a discussion about this recently in the Apple Core Animation forum on Apple's site, and an Apple engineer who goes by "Rincewind" posted that the layer filters feature is not implemented for iOS at all.

The documentation says:

iOS Note: While the CALayer class in iOS exposes the filters property, Core Image is not available. Currently the filters available for this property are undefined.

As far as I know you can only use CI filters by calling them directly and getting back a CIImage as output. You then have to use the CIImage through code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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